2012-06-16 59 views
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(「因爲不同的線程擁有它調用線程不能訪問該對象」)這種事發生在不同的線路,每次我運行程序,不要讓我看到錯誤在哪裏(「沒有可用的源代碼」)(當我在方法內部調試時出現的異常總是出現在「軍人()」,但不總是在同一行)請幫助我!無效操作異常線程

+0

請顯示一個簡短的*完整*程序來展示問題。 –

回答

0

既然你沒有指定我假設你使用wpf。

您只能從主UI線程訪問DependencyProperties。可能發生的是,一個或多個變量cuadroactual1,cuadroactual3,cuadrofinal,lectorreproductorlisto1被聲明爲DependencyProperties,並且當其中一個線程嘗試訪問它們時拋出異常。