线程thread

 Thread a = new Thread(showMsg);
            a.IsBackground = true;
            a.Start();

**************************************************************8

 public  void showMsg()
        {
            lock (locker)
            {
                while (true)
                {
                    Action a = () =>
                    {                      
                        getName();
                    };
                    this.Dispatcher.BeginInvoke(a);
                    //textBlock.Dispatcher.BeginInvoke(a);
                    Thread.Sleep(1000);
                }
            }           
        }
        int i = 0;
        int sum;
        private void getName()
        {
            i++;
            int iResult;
            Random ro = new Random();
            iResult = ro.Next(0, 1000);
            int a =  iResult;
            textBox.AppendText(a+"  ") ;
            textBox.ScrollToEnd();
            sum += a;
            textBlock.Text = sum.ToString();
        }

 

 

 

 

posted @ 2019-07-26 09:32  算法工程师~Allen  阅读(108)  评论(0编辑  收藏  举报