private void openDeviceCallback(IAsyncResult r) { AsyncResult aResult = (AsyncResult)r; openDviceDelegate d = (openDviceDelegate)aResult.AsyncDelegate; string id = d.EndInvoke(r); //openDviceDelegate d = ((openDviceDelegate)r.).EndInvoke(r); E7.iDevice = Convert.ToInt32(id); ((Control)r.AsyncState).Invoke(new Action(() => { MessageBox.Show(id); })); Console.WriteLine("操作完成!" + r.AsyncState); }
/// <summary> /// /// </summary> /// <param name="Idl">显示的主窗体,用于回调函数显示值</param> /// <returns></returns> public string openDevice(Control Idl) { try { openDviceDelegate openDvice = initDevice; IAsyncResult result = openDvice.BeginInvoke(openDeviceCallback, Idl); } catch { } //string idDevice = openDvice.EndInvoke(result); //return idDevice; return(""); }