Heretiiik

Untitled

Oct 25th, 2019
265
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.16 KB | None | 0 0
  1. public class Terminator : INotifyPropertyChanged
  2. {
  3.     private bool terminate;
  4.     public event PropertyChangedEventHandler PropertyChanged;
  5.  
  6.     private void NotifyPropertyChanged([CallerMemberName] String propertyName = "")
  7.     {
  8.         PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
  9.     }
  10.     public bool Terminate
  11.     {
  12.         get
  13.         {
  14.             return this.terminate;
  15.         }
  16.         set
  17.         {
  18.             if (value != this.terminate)
  19.             {
  20.                 this.terminate = value;
  21.                 NotifyPropertyChanged();
  22.             }
  23.         }
  24.     }
  25.  
  26.     public PlayerThreadNotify(bool terminate = false)
  27.     {
  28.         this.terminate = terminate;
  29.     }
  30. }
  31.  
  32. public class SomeClass {
  33.  
  34.     public SomeClass(Terminator t) {
  35.         t.PropertyChanged += Teminator_PropertyChanged;
  36.     }
  37.  
  38.     public void LongRunningMethod(Terminator t) {
  39.         /// .. do work
  40.     }
  41.  
  42.     private void Teminator_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) {
  43.         /// .. handle that LongRunningMethod should stop
  44.     }
  45.  
  46.    
  47. }
  48.  
  49. public static void ThreadFunc(Terminator t) {
  50.     var obj = new SomeClass(t);
  51.     obj.LongRunningMethod(t);
  52. }
Advertisement
Add Comment
Please, Sign In to add comment