void CounterThread() { int cnt = 0; while (!stopReq.Token.IsCancellationRequested) { Thread.Sleep(50); cnt++; if (Count != null) { if (SynchronizationContext == null) { foreach (var del in Count.GetInvocationList()) { var target = del.Target as ISynchronizeInvoke; if (target != null) { if (InvokeSynchronized) { target.Invoke(del, new object[] { this, new CounterEventArgs(cnt) }); } else { target.BeginInvoke(del, new object[] { this, new CounterEventArgs(cnt) }); } } } } else { var args = new CounterEventArgs(cnt); if (InvokeSynchronized) { SynchronizationContext.Send(delegate { Count(this, args); }, null); } else { SynchronizationContext.Post(delegate { Count(this, args); }, null); } } } } }
void HandleCount6(object sender, CounterEventArgs e) { l6.Text = e.Cnt.ToString(); }