TO:Samen168(Samen)主要是想说明我做的过程中所遇到的问题。多谢赐教!

解决方案 »

  1.   

    当然会死机,在看看CPU占用是不是100%了?
    无限循环 至少也要写成
    while(true)
    {
    Thread.Sleep(10); m_dResult += 13;
    textBox_Result.Text = m_dResult.ToString();
    }吧.
      

  2.   

    同意 zhiang75(zhiang75) ,到少要把临界区让出来给另一个线程用。
      

  3.   

    public void ThreadA()
      {
             while(true)
    {
             Thread.Sleep(10);
    m_dResult += 13;
    textBox_Result.Text = m_dResult.ToString();
    }
      }
    public void ThreadB()
      {
    while(true)
    {
             Thread.Sleep(10);
    m_dResult -= 11;
    textBox_Result.Text = m_dResult.ToString();
    }
      }
      

  4.   

    参考AutoResetEvent类,里面有个例子如下,应该对你有所帮助using System;
    using System.Threading;namespace AutoResetEvent_Examples
    {
        class MyMainClass
        {
            //Initially not signaled.
          const int numIterations = 100;
          static AutoResetEvent myResetEvent = new AutoResetEvent(false);
          static int number;
          
          static void Main()
            {
             //Create and start the reader thread.
             Thread myReaderThread = new Thread(new ThreadStart(MyReadThreadProc));
             myReaderThread.Name = "ReaderThread";
             myReaderThread.Start();         for(int i = 1; i <= numIterations; i++)
             {
                Console.WriteLine("Writer thread writing value: {0}", i);
                number = i;
                
                //Signal that a value has been written.
                myResetEvent.Set();
                
                //Give the Reader thread an opportunity to act.
                Thread.Sleep(0);
             }         //Terminate the reader thread.
             myReaderThread.Abort();
          }      static void MyReadThreadProc()
          {
             while(true)
             {
                //The value will not be read until the writer has written
                // at least once since the last read.
                myResetEvent.WaitOne();
                Console.WriteLine("{0} reading value: {1}", Thread.CurrentThread.Name, number);
             }
          }
        }
    }
      

  5.   

    看一下ManualResetEvent这个类的用法;
      

  6.   

    我觉得你这个程序没什么需要同步的,线程同步主要用在多个线程共用一些独享资源时,一个线程在使用时,另一个线程不能使用,要等到其用完了,发个信号出来,另一个线程才可以用。而你程序中m_dResult不是独享或需要其他条件的,谈不上要同步,并且也不会有如果不同步会出现错误或不合理。个人观点,仅供参考。