Is it possible to run a progressbar in windows phone 8 on a separate thread, or using the Dispatcher class?
thanx
Is it possible to run a progressbar in windows phone 8 on a separate thread, or using the Dispatcher class?
thanx
put ur progress bar in App.xaml
<ProgressBar IsIndeterminate="True" HorizontalAlignment="Stretch" VerticalAlignment="Top" Loaded="ProgressBar_Loaded" Visibility="Collapsed" />
& then put this c# code into 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;
}
}
define a separate method in a 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;
}
}
now u have separate method to show or hide the progress bar
call it in a dispature, so it wont freez ur UI
--->
Dispatcher.BeginInvoke(() => { RestMethods.ShowProgress(true); }); // to show
Dispatcher.BeginInvoke(() => { RestMethods.ShowProgress(false); }); // to hide
UI controls in WindowsPhone can be updated just from UI thread and it is not possible to update ProgressBar
from separate (not UI) thread. Dispatcher
just will marshal a call from working thread to UI thread.