2011-08-15 116 views
0

我陷入了一個小問題: 我寫了一個通信類,當數據到達時觸發OnResponseData。 現在我需要檢查調用者是活動本身還是類。檢查RunOnUiThread是否有必要?

看到這個代碼:

private void OnResponseData(ushort ID, byte function, byte[] values) 
{ 
#if (winm || win7) // windows mobile or phone 7 
    if (this.m_Container.Form.InvokeRequired) 
     { 
      this.m_Container.Form.BeginInvoke(new ModbusTCP.Master.ResponseData(OnResponseData), new object[] { id, function, values }); 
      return; 
     } 
#else 
    if (??) // well this is the problem, what i need to check here? 
    { 
     Action newAc; 
     newAc = delegate { OnResponseData(ID, function, values); }; 
     this.m_Container.Form.RunOnUiThread(newAc); 
     return; 
    } 
#endif 
... 

this.m_Container.Form是我Activity 我基本上需要InvokeRequired爲Android。

到目前爲止感謝。

回答

0
(this.m_Container instanceOf Activity) 

這是否解決了問題!

+0

因爲instanceOf沒有在c#中定義我試過了。但是沒有效果。有人有另一個想法? – Eun

+0

相當於Java的'instanceof'關鍵字的C#是''關鍵字:'if(this.m_Container是Activity)...' – jonp