private void Start() { waiterDelegate = GetComponent <WaiterDelegate>(); if (inWaiters.Count == 0) { Activate(); } else { state = WaitersState.deactivated; } }
private static void WaitForFiles(string currentWorkingDirectory, IEnumerable <string> files, bool caseInsensitive, int timeout, WaiterDelegate waiter) { string errorMessage = waiter(currentWorkingDirectory, files, caseInsensitive, timeout); if (errorMessage != null) { string newErrorMessage = waiter(currentWorkingDirectory, files, caseInsensitive, timeout); if (newErrorMessage != null) { errorMessage = String.Concat(errorMessage, "\r\nFailed even when forcing completion with double timeout"); } else { errorMessage = String.Concat(errorMessage, "\r\n*Didn't* fail when forcing completion with double timeout"); } throw new TimeoutException(errorMessage); } }
public void WindowsWait(SynchronizationContext context, Canceler cancel) { AsyncWaitHandleCreate.Reset(); AsyncWaitHandleClose.Reset(); //выражение, включающее - выключающее формы Action <Boolean> switchingWindows = (Boolean enable) => { foreach (System.Windows.Forms.Form window in System.Windows.Forms.Application.OpenForms) { if (window.Visible) { if (enable) { window.Cursor = System.Windows.Forms.Cursors.Default; } else { window.Cursor = System.Windows.Forms.Cursors.WaitCursor; } window.Enabled = enable; } } }; context.Send((object state) => switchingWindows(false), null); //ассинхронная операция, выполняющая ожидание WaiterDelegate waiterAction = (SynchronizationContext graphicsContext, Canceler canceler) => { AsyncWaitHandleCreate.Set(); Int32 counter = 0; try { do { if (canceler.ThrowIfCancellationRequested()) { break; } Thread.Sleep(50); //20HZ процесс } while((COUNTER_MAX * 20) >= ++counter); } catch (OperationCanceledException ex) { Lib.Win.Data.Env.WriteToLog(ex); } AsyncWaitHandleClose.Set(); return(graphicsContext); }; waiterAction.BeginInvoke(context, cancel, (IAsyncResult ar) => { var waiterActionEnd = ar.AsyncState as WaiterDelegate; if (waiterActionEnd != null) { waiterActionEnd.EndInvoke(ar); } if (ar.CompletedSynchronously) { switchingWindows(true); } else { context.Send( (object state) => switchingWindows(true), null); } }, waiterAction); //ожидание запуска waiterAction AsyncWaitHandleCreate.WaitOne(5000); }