我在winform程序里,使用mediaplayer对象(.net3.5),mediaplayer对象是在FormMain中实例化的,使用另外一个线程控制它时,出现错误提示:The calling thread cannot access this object because a different thread owns it.
请问这是什么问题啊,该如何解决?
怎样能够防卫另外一个线程的对象?

解决方案 »

  1.   

    //定义代理ShowStatus
            private delegate void ShowStatus(string str);
            ShowStatus showStatus = new ShowStatus(DoShowStatus);//用来更新界面元素的函数
            private void DoShowStatus(string txt)
            {
                lock (this)
                {
                    //sta_SysStatus是界面控件
                    sta_SysStatus.Text = txt;
                }
            }//调用
             //其它线程中调用
            mainform.BeginInvoke(showStatus);
    原理是这样的,用委托来调用其它线程的函数
      

  2.   

    DoShowStatus是不是需要是静态方法呢?
      

  3.   

    不需要,只要在线程中可以看到就可以了 具体就是这个函数在mainform中设计,用public就可以