コード例 #1
0
        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);
                        }
                    }
                }
            }
        }
コード例 #2
0
ファイル: MultithreadingSample.cs プロジェクト: m13253/xwt
		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);
						}
					}
				}
			}
		}
コード例 #3
0
 void HandleCount6(object sender, CounterEventArgs e)
 {
     l6.Text = e.Cnt.ToString();
 }
コード例 #4
0
ファイル: MultithreadingSample.cs プロジェクト: m13253/xwt
		void HandleCount6 (object sender, CounterEventArgs e)
		{
			l6.Text = e.Cnt.ToString ();
		}