Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Terminator : INotifyPropertyChanged
- {
- private bool terminate;
- public event PropertyChangedEventHandler PropertyChanged;
- private void NotifyPropertyChanged([CallerMemberName] String propertyName = "")
- {
- PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
- }
- public bool Terminate
- {
- get
- {
- return this.terminate;
- }
- set
- {
- if (value != this.terminate)
- {
- this.terminate = value;
- NotifyPropertyChanged();
- }
- }
- }
- public PlayerThreadNotify(bool terminate = false)
- {
- this.terminate = terminate;
- }
- }
- public class SomeClass {
- public SomeClass(Terminator t) {
- t.PropertyChanged += Teminator_PropertyChanged;
- }
- public void LongRunningMethod(Terminator t) {
- /// .. do work
- }
- private void Teminator_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) {
- /// .. handle that LongRunningMethod should stop
- }
- }
- public static void ThreadFunc(Terminator t) {
- var obj = new SomeClass(t);
- obj.LongRunningMethod(t);
- }
Advertisement
Add Comment
Please, Sign In to add comment