private void _4() { //Probably equivalent like _2() WaitDelegate wd = Wait; IAsyncResult ar = wd.BeginInvoke(3000, null, null); while (ar.AsyncWaitHandle.WaitOne(50, true)) /* waiting */ } {
public void WaitConnectionAsync() { if (connectState == ConnectState.born) { connectState = ConnectState.waitingConnection; waitDelegate.BeginInvoke(null, null); } }
//Global variable for example _3 - not necessery (see third parameter BeginInvoke in _3) //private WaitDelegate wd; private void _3() { WaitDelegate wd = Wait; //Equivalent, but parameters are seen //AsyncCallback ac = new AsyncCallback(WaitCallback) //Is properly passing delegate instance like third (object) parameter IAsyncResult ar = wd.BeginInvoke(1000, WaitCallback, wd); }
public void WaitConnectionAsync() { if (connectState == ConnectState.born) { connectState = ConnectState.waitingConnection; Console.WriteLine("名前付きパイプ:接続待ち開始"); waitDelegate.BeginInvoke(null, null); } }
/// <summary> /// Waits for millis milliseconds /// </summary> /// <param name="millis"></param> public void wait(int millis) { Wait wait = new Wait(); WaitDelegate wDel = new WaitDelegate(wait.waitFor); System.Console.WriteLine("CALLING WAIT " + millis); isSleep = true; wDel.BeginInvoke(millis, new AsyncCallback(CallBackMethod), wDel); }
public void sendRoomData(ConnectedUser User) { WaitDelegate X = new WaitDelegate(sendRoomData2); IAsyncResult ar = X.BeginInvoke(User, null, null); ar.AsyncWaitHandle.WaitOne(1000, false); if (ar.IsCompleted) { X.EndInvoke(ar); } }
private void _2() { //Cyclic polling WaitDelegate wd = Wait; IAsyncResult ar = wd.BeginInvoke(2000, null, null); //Running while (!ar.IsCompleted) { Console.WriteLine("!ar.IsCompleted"); Thread.Sleep(100); } //Get result int res = wd.EndInvoke(ar); Console.WriteLine(res); //If the main process is terminated, so subprocess is terminate too }
public void sendRoomData(ConnectedUser User) { WaitDelegate X = new WaitDelegate(sendRoomData2); IAsyncResult ar = X.BeginInvoke(User, null, null); ar.AsyncWaitHandle.WaitOne(1000, false); if (ar.IsCompleted) { X.EndInvoke(ar); } }
/// <summary> /// Waits for millis milliseconds /// </summary> /// <param name="millis"></param> public void wait(int millis) { Wait wait = new Wait(); WaitDelegate wDel = new WaitDelegate(wait.waitFor); System.Console.WriteLine("CALLING WAIT " + millis); isSleep = true; wDel.BeginInvoke(millis, new AsyncCallback(CallBackMethod), wDel); }