Progressbar windows phone 8个独立的线程

时间:2013-06-26 13:58:54

标签: multithreading windows-phone-8 progress-bar dispatcher

是否可以在单独的线程上使用Windows Phone 8运行进度条,或使用Dispatcher类?

感谢名单

2 个答案:

答案 0 :(得分:3)

将您的进度条放在App.xaml

<ProgressBar IsIndeterminate="True" HorizontalAlignment="Stretch" VerticalAlignment="Top" Loaded="ProgressBar_Loaded" Visibility="Collapsed" />

&安培;然后将此c#代码放入ur App.xaml.cs

public partial class App : Application
    {
        // progress bar
        public ProgressBar m_progressBar;
        // some code......


        private void ProgressBar_Loaded(object sender, RoutedEventArgs e)
        {
            m_progressBar = (ProgressBar)sender;
        }
    }

class

中定义单独的方法
public static Class RestMethods
{
   public static void ShowProgress(bool show)
        {
            if (show)
                ((App)Application.Current).m_progressBar.Visibility = Visibility.Visible;
            else
                ((App)Application.Current).m_progressBar.Visibility = Visibility.Collapsed;
        }
}

现在你有单独的方法来显示或隐藏进度条

以调度方式调用它,因此它不会自由地UI ---&gt;

Dispatcher.BeginInvoke(() => { RestMethods.ShowProgress(true); });    // to show
Dispatcher.BeginInvoke(() => { RestMethods.ShowProgress(false); });    // to hide

答案 1 :(得分:0)

WindowsPhone中的UI控件只能从UI线程更新,并且无法从单独的(非UI)线程更新ProgressBarDispatcher只会编组从工作线程到UI线程的调用。