我陷入了一个小问题: 我写了一个通信类,当数据到达时触发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。
到目前为止感谢。
因为instanceOf没有在c#中定义我试过了。但是没有效果。有人有另一个想法? – Eun
相当于Java的'instanceof'关键字的C#是''关键字:'if(this.m_Container是Activity)...' – jonp