简体   繁体   English

无效的操作异常线程

[英]invalid operation exception threads

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++;
            }

    }

when i execute the program it throws an InvalidOperationException ("The calling thread cannot access this object because a different thread owns it") this happen in different lines everytime I run the program and do not let me see where the mistake is ("No source available").(The exception always appear when I am debuggin inside of the method "junta()" but not always in the same line) Please help me! 当我执行程序时,它将引发InvalidOperationException(“调用线程无法访问该对象,因为其他线程拥有它”),这在每次运行程序时都发生在不同的行中,并且不要让我看到错误的位置(“无源(可用)。(当我在方法“ junta()”中调试时,总是会出现异常,但并不总是在同一行中)。请帮助我!

Since you did not specify I'm assuming you use wpf. 由于您未指定,因此我假设您使用wpf。

You can only access DependencyProperties from the main UI thread. 您只能从主UI线程访问DependencyProperties。 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. 什么是可能发生的是,在以上的变量cuadroactual1cuadroactual3cuadrofinallectorreproductorlisto1被宣布为DependencyProperties,当一个线程试图访问他们抛出异常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM