Guarantees execution of ITasks in a sequence.
Namespace: Dapfor.Net.ThreadingAssembly: Dapfor.Net (in Dapfor.Net.dll) Version: 2.10.3.24917 (2.10.3.24917)
Syntax
C# |
---|
public class Sequencer |
Visual Basic |
---|
Public Class Sequencer |
Visual C++ |
---|
public ref class Sequencer |
F# |
---|
type Sequencer = class end |
Remarks
Only one ITask can be executed at the moment. Following example demonstrates how to implement thread-safe event in data object:
Copy | |
---|---|
class MyClass : INotifyPropertyChanged { private Sequencer sequencer = new Sequencer(); private PropertyChangedEventHandler internalPropertyChanged; //Implementation of the thread-safe event public event PropertyChangedEventHandler PropertyChanged { add { //Do subscription in sequence sequencer.ProcessTask(new DelegateTask(delegate { internalPropertyChanged += value; })); } remove { //Remove subscription in sequence sequencer.ProcessTask(new DelegateTask(delegate { internalPropertyChanged -= value; })); } } public void NotifyUpdate(string propertyName) { //Send notification in sequence. sequencer.ProcessTask(new DelegateTask(delegate { //Here we don't need to acquire the lock object. All notification are processed in sequence. if(internalPropertyChanged != null) { internalPropertyChanged(this, new PropertyChangedEventArgs(propertyName)); } })); } } |