如题
我用了个全局变量可以解决这个问题
但是我不知道线程间如何发送消息
在这里请教各位朋友

解决方案 »

  1.   

    http://topic.csdn.net/u/20080117/14/e967988a-295c-40c2-a571-4be0516b1e82.html
      

  2.   


    public partial class Form1 : Form
    {
        Thread progress;    private void Form1_Load(object sender, EventArgs e)
        {
            progress = new Thread(new ThreadStart(Run));
        }    private void button1_Click(object sender, EventArgs e)
        {
            progress.Start();
        }    public void Run()
        {
            try
            {
                //......
            }
            catch (Exception err)
            {
                //在这里如何让主线程的textbox显示err.Message
            }
        }        }
      

  3.   

    有的全局变量解决不了的。
    SynchronizationContext.Current获取线程的同步对象,使用该对象的Post,可以向线程发送消息,要求该线程去执行某个委托
      

  4.   

    delegate void ShowErrorHandler(string text);void ShowError(string text)
    {
      if(textbox.InvokeRequired)
     {
      ShowErrorHandler seh = ShowError;
      this.Invoke(seh,new object[]{text});
     }else{
      textbox.Text = text;
     }
    }
      

  5.   

        public void Run()
        {
            try
            {
                //......
            }
            catch (Exception err)
            {
                //在这里如何让主线程的textbox显示err.Message
                ShowError(err.Message);
            }
        }