0
tpide1=new Thread(new ThreadStart(pide1));
        tjunta=new Thread(new ThreadStart(junta));
public void pide1() 
    {
        while (cuadroactual1 < cuadrofinal) 
        {
            if (cuadroactual3 == cuadroactual1 )
            {
                lector.lee1(cuadroactual1);
                cuadroactual1++;
                reproductorlisto1.Set();
            }
        }
    }


    public void junta() 
    {

        while (cuadroactual3 < cuadrofinal)
        {
            AutoResetEvent.WaitAll(estanlistos);

                lector.junta(cuadroactual3);
                canvasjuntar.Dispatcher.Invoke((Action)(() => {  canvasjuntar.Background = new ImageBrush(lector.BMS); }));
                cuadroactual3++;
            }

    }

当我执行程序时,它会抛出 InvalidOperationException(“调用线程无法访问此对象,因为不同的线程拥有它”)每次我运行程序时都会在不同的行中发生这种情况,并且不要让我看到错误在哪里(“无源可用”)。(当我在方法“junta()”中调试时总是出现异常,但并不总是在同一行)请帮助我!

4

1 回答 1

0

Since you did not specify I'm assuming you use wpf.

You can only access DependencyProperties from the main UI thread. What is probably happening is that on or more of your variables cuadroactual1, cuadroactual3, cuadrofinal, lector or reproductorlisto1 were declared as DependencyProperties and the exception is thrown when one of the threads tries to access them.

于 2012-06-16T07:14:34.993 回答