private static void ShutdownDispatcher(Dispatcher dispatcher, Countdown countdown) { EventHandler handler = null; if ((dispatcher != null) && !dispatcher.HasShutdownFinished) { countdown.Increment(); try { if (handler == null) { handler = (sender, e) => countdown.Decrement(); } dispatcher.ShutdownFinished += handler; if (dispatcher.HasShutdownFinished) { countdown.Decrement(); } else { dispatcher.BeginInvokeShutdown(DispatcherPriority.Send); } } catch { countdown.Decrement(); } } }
private void RunQuery(QueryRunner runner) { Action<Task> continuationAction = null; Action a = null; object obj2; runner.Prepare(); this.QueryCompletionCountdown = new Countdown(); this.Disposables = new List<IDisposable>(); this.LambdaFormatter = new XhtmlWriter(false, false); LINQPadDbController.SqlLog = new StringWriterEx(0xf4240); DataContextBase.SqlLog = LINQPadDbController.SqlLog; this.ResultsWriter = new XhtmlWriter(true, true); this._explorables = this.ResultsWriter.Explorables; Console.SetOut(this.ResultsWriter); Console.SetIn(new ConsoleTextReader(new Func<string>(this.ReadLine))); Debug.Listeners.Clear(); Debug.Listeners.Add(new TextWriterTraceListener(this.ResultsWriter)); XhtmlFormatter.ResetTableID(); lock ((obj2 = this._statusLocker)) { if (this._cancelRequest) { return; } } object obj3 = null; try { obj3 = runner.Run(); } catch (Exception exception) { this.PostStatus(this.GetStatusArgs(exception, false, true)); } if (obj3 is Task) { this.QueryCompletionCountdown.Increment(); QueryStatusEventArgs args = new QueryStatusEventArgs("Query continuing asynchronously...") { ExecutionComplete = false, Async = true }; this.PostStatus(args); if (continuationAction == null) { continuationAction = delegate (Task ant) { try { Exception ex = this.GetTaskException(ant); if (ex != null) { this._faulted = true; this.PostStatus(this.GetStatusArgs(ex, true, true)); } } catch { } this.QueryCompletionCountdown.Decrement(); }; } ((Task) obj3).ContinueWith(continuationAction); } if (this.QueryCompletionCountdown.Value <= 0) { this._executionStopwatch.Stop(); } lock ((obj2 = this._statusLocker)) { if (this._cancelRequest) { return; } } PluginForm pluginForm = null; pluginForm = this.PrepareMessageLoop(); if (pluginForm != null) { this.QueryCompletionCountdown.Increment(); } if (this.QueryCompletionCountdown.Value <= 0) { this.PostStatus(this.GetStatusArgs(null, true, true)); this.PerformCompletionCleanup(false, false); } else { QueryStatusEventArgs args2 = new QueryStatusEventArgs("Query continuing asynchronously...") { ExecutionComplete = false, Async = true }; this.PostStatus(args2); if (a == null) { a = delegate { this.PostStatus(this.GetStatusArgs(null, true, true)); this.PerformCompletionCleanup(false, false); }; } this.QueryCompletionCountdown.ContinueWith(a); } this.RunMessageLoop(pluginForm, true); }
public static void ShutdownWPF(bool waitUntilDone) { // This item is obfuscated and can not be translated. ShutdownCurrentDispatcher(); Countdown countdown = new Countdown(); try { foreach (Dispatcher dispatcher in GetActiveDispatchers()) { ShutdownDispatcher(dispatcher, countdown); } } finally { if (waitUntilDone) { while (countdown.Wait(0x1388)) { Label_004C: if (0 == 0) { goto Label_006E; } } goto Label_004C; } Label_006E:; } }