大侠帮忙看一看,错在哪  初学多线程,把别人的搬过来,运行不了,帮帮吗啊
        private void frmPrinciple_Load(object sender, EventArgs e)
        {
            Startform = new frmStart();
            Thread t = new Thread(new ThreadStart(display));
            t.Start();
            Startform.ShowDialog();  
        }
        display
        {
            //do something
            Startform.Stop = true;
        }    public delegate void frmCloseHandler();
  
    public partial class frmStart : Form
    {
        private bool IsStop ;
        private Thread t;
        public bool Stop
        {
            set { IsStop = value; }
        }
        public frmStart()
        {
            InitializeComponent();
        }
        private void FrmStart_Load(object sender, EventArgs e)
        {
            IsStop = false;
            t = new Thread(new ThreadStart(closeThisForm));
            t.Start();        }
        private void closeThisForm()
        {
            if (this.InvokeRequired)
            {
                frmCloseHandler close = new frmCloseHandler(closeThisForm);
                this.Invoke(close);
            }
            else
            {
                this.Close();
            }
            IsStop = false;
        }
        private void FrmStart_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (t != null) t.Abort();
            for (float i =100; i>=1; i--)
            {
                Thread.Sleep(10);
                Opacity = i / 100;
            }
        }
    }
        

解决方案 »

  1.   

    你给讲讲 if (this.InvokeRequired)
      {
      frmCloseHandler close = new frmCloseHandler(closeThisForm);
      this.Invoke(close);
      }
      else
      {
      this.Close();
      }
    啥意思 我菜鸟别笑话啊
      

  2.   

    Control.InvokeRequired 属性
    获取一个值,该值指示调用方在对控件进行方法调用时是否必须调用 Invoke 方法,因为调用方位于创建控件所在的线程以外的线程中。 意思是跨线程访问,需要使用控件的Invoke方法来调用一个委托,回调的形式执行代码,目的是同步线程和ui线程。http://msdn.microsoft.com/zh-cn/library/system.windows.forms.control.invokerequired(VS.80).aspxhttp://www.cnblogs.com/zyh-nhy/archive/2007/12/25/1014749.html
      

  3.   

     private void display()
            {
                string sourcefilename = System.Windows.Forms.Application.StartupPath + "//Data//系统总则.doc";
                object fileName = sourcefilename;
                object readOnly = false;
                object isVisible = true;
                object missing = System.Reflection.Missing.Value;            Microsoft.Office.Interop.Word.Application wordapp = new Microsoft.Office.Interop.Word.Application();
                wordapp.Visible = false;
                Microsoft.Office.Interop.Word.Document aDoc = wordapp.Documents.Open(ref fileName, ref missing,
                    ref readOnly, ref  missing, ref missing, ref  missing, ref  missing, ref  missing, ref  missing,
                    ref  missing, ref missing, ref  isVisible, ref missing, ref missing, ref missing, ref missing);
                wordapp.Selection.WholeStory();
                wordapp.Selection.Copy();
                richTextBox1.Paste();
                wordapp.Application.Quit(ref missing, ref missing, ref missing);
                Startform.Stop = true;
            }
    这是display()方法  老提示“线程间操作无效: 从不是创建控件“richTextBox1”的线程访问它。”
      

  4.   

     richTextBox1.Paste();
    这句处 出错  我把this.InvokeRequired改为richTextBox1后不出错,但richTextBox1上面什么内容都没有
      

  5.   

    tryprivate void display()
    {
    string sourcefilename = System.Windows.Forms.Application.StartupPath + "//Data//系统总则.doc";
    object fileName = sourcefilename;
    object readOnly = false;
    object isVisible = true;
    object missing = System.Reflection.Missing.Value; Microsoft.Office.Interop.Word.Application wordapp = new Microsoft.Office.Interop.Word.Application();
    wordapp.Visible = false;
    Microsoft.Office.Interop.Word.Document aDoc = wordapp.Documents.Open(ref fileName, ref missing,
    ref readOnly, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing,
    ref missing, ref missing, ref isVisible, ref missing, ref missing, ref missing, ref missing);
    wordapp.Selection.WholeStory();
    wordapp.Selection.Copy();
    richTextBox1.Invoke((EventHandler)delegate{richTextBox1.Paste();});
    wordapp.Application.Quit(ref missing, ref missing, ref missing);
    Startform.Stop = true;
    }
      

  6.   

            private void SetText(string str)
            {
                if (this.richTextBox1.InvokeRequired)
                {
                    this.richTextBox1.Invoke(new SetTextHandler(this.SetText), new object[] { str });
                }
                else
                {
                    this.richTextBox1.AppendText(string.Format("{0}:{1}\r\n", DateTime.Now, str));
                }
            }
      

  7.   

    把this.InvokeRequired 改为richTextBox1.InvokeRequird 吗               richTextBox1.Invoke((EventHandler)delegate{richTextBox1.Paste();});这是啥意思 通俗点
      

  8.   

    richTextBox1.Invoke
    这句话的意思是给这个控件的UI线程添加一个委托
    简单的讲,就是给他注册一个方法,并不是多线程。