public SimulatorForm()
{
InitializeComponent();
this.SetStyle(
ControlStyles.AllPaintingInWmPaint |
ControlStyles.UserPaint |
ControlStyles.DoubleBuffer, true);
this.updateActions = new List<Action>();
this.cancelSource = new System.Threading.CancellationTokenSource();
this.senderTask = new Task(x =>
{
while (!this.cancelSource.IsCancellationRequested)
{
lock (this.updateActions)
{
foreach (var action in this.updateActions)
action();
}
System.Threading.Thread.Sleep(100);
}
}, this.cancelSource.Token, TaskCreationOptions.LongRunning);
this.senderTask.Start();
}