Advertisement
Guest User

Untitled

a guest
Jul 17th, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. public partial class MainWindow : Window
  2. {
  3. ......
  4. private RX consumer = new RX();
  5.  
  6. private void Window_Loaded(object sender, RoutedEventArgs e)
  7. {
  8. try
  9. {
  10. Task backgroundDBTask = Task.Factory.StartNew(() => { Consumer(consumer);}, TaskCreationOptions.LongRunning);
  11. }
  12. }
  13.  
  14. public void Consumer(Consumer consumer)
  15. {
  16.  
  17. while (true)
  18. {
  19. Thread.Sleep(1000);
  20. .......
  21. Dispatcher.BeginInvoke(new Action(() =>
  22. {
  23. mylbl.Content = value.ToString();
  24. }), DispatcherPriority.Background);
  25. }
  26. }
  27.  
  28. public partial class MainWindow : Window
  29. {
  30. ....
  31. private RX consumer = new RX();
  32.  
  33. private void Window_Loaded(object sender, RoutedEventArgs e)
  34. {
  35. try
  36. {
  37. Task backgroundDBTask = Task.Factory.StartNew(() => { consumer.ProcessMessages(); }, TaskCreationOptions.LongRunning);
  38. }
  39. }
  40.  
  41. }
  42.  
  43.  
  44. public class RX
  45. {
  46.  
  47. public void ProcessMessages()
  48. {
  49.  
  50. while (true)
  51. {
  52. Thread.Sleep(1000);
  53.  
  54. ....
  55.  
  56. var m_dispatcher = Application.Current.MainWindow;
  57.  
  58. m_dispatcher.Dispatcher.BeginInvoke(new Action(() =>
  59. {
  60. mylbl.Content = value.ToString();
  61. }), DispatcherPriority.Background);
  62.  
  63. }
  64. }
  65.  
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement