Video of the week

I've found this great video and I recommend you to watch if you are interested in wireshark and filtering methods

ParameterizedThreadStart - PerformanceProgressBar - Transition between two pages in WP7

ParameterizedThreadStart - PerformanceProgressBar - example of use - transition between two XAML pages

Hi, today I would like to describe (a little) my way to achieve an effect of page-initialization process using PerformanceProgressBar. I will put Visual Studio project file here later - very simple and marked in most important places to avoid going through unimportant parts of code. First of all I will explain my concept - I've got two pages and when I navigate from Page1 to Page2 - until Page2 gets loaded whole initialization process is being performed. During initialization process I can see some dots going from left to right (PerformanceProgressBar) and TextBlock object with "Loading...." as its Text's value.

When Page2 is being loaded I start new Thread object and do some initialization stuff in DoWork method (parameter of ParameterizedThreadStart delegate). I invoke this method with 2-second delay so PerformanceProgressBar can be displayed at least in one cycle. Use of Dispatcher is the most important because it helps to avoid invalid cross thread issue.

In my DoWork method I make my MainPivot container visible again and hide MainStackPanel which is a container for TextBlock ("Loading....") and PerformanceProgressBar - that's it. You have to add reference to the Microsoft.Phone.Controls.Toolkit and add xmlns : xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"

  1. // HERE
  2. private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
  3. {
  4. ParameterizedThreadStart pts = new ParameterizedThreadStart(DoWork);
  5. Thread t = new Thread(pts);
  6. // Set 2-second delay as the parameter of DoWork method
  7. t.Start(2000);
  8. }
  9.  
  10. // HERE
  11. public void DoWork(object milliseconds)
  12. {
  13. // Wait..
  14. Thread.Sleep((int)milliseconds);
  15. // and after 2 seconds:
  16.  
  17. // DO SOMETHING HERE (..)
  18.  
  19. Dispatcher.BeginInvoke((ThreadStart)delegate()
  20. {
  21. // Hide MainStackPanel
  22. this.MainStackPanel.Visibility = System.Windows.Visibility.Collapsed;
  23. // Disable PerformanceProgressBar
  24. this.PerformanceProgressBar.IsEnabled = false;
  25. // Make MainPivot visible
  26. this.MainPivot.Visibility = System.Windows.Visibility.Visible;
  27. },
  28. null);
  29. } // end of DoWork method

 

 

page1

performanceprogressbar

page2