示例#1
0
文件: Form2.cs 项目: ChabanovSN/Quize
        private void Run(object state)
        {
            SynchronizationContext perant = state as SynchronizationContext;

            // смотри id потока

            int id = Thread.CurrentThread.ManagedThreadId;

            Console.WriteLine("Run thread: " + id);


            for (int i = 0; i < 1; i++)
            {
                //Thread.Sleep(10);

                try
                {
                    // perant.Post(UpdateUI, "line " + i.ToString());
                    //   perant.Send(UpdateUI, "line " + i.ToString());
                    //   perant.Post(UpdateUI2, "line " + i.ToString());
                    perant.PostRight(UpdateUI2, "line " + i.ToString());
                    //   perant.Send(UpdateUI2, "line " + i.ToString());
                }
                catch (MyException e)
                {
                    Console.WriteLine("Run thread MyException: " + id + " " + e.Message1);
                }
                catch (System.Reflection.TargetInvocationException e)
                {
                    MyException my = e.InnerException as MyException;
                    Console.WriteLine("Run thread TargetInvocationException-> MyException: " + id + " " + my?.Message1);
                }
                catch (Exception e)
                {
                    Console.WriteLine("Run thread Exception: " + id + " " + e?.Message);
                }
            }
        }