diff --git a/ILSpy/TextView/DecompilerTextView.cs b/ILSpy/TextView/DecompilerTextView.cs index 648a9dbd9..55204e511 100644 --- a/ILSpy/TextView/DecompilerTextView.cs +++ b/ILSpy/TextView/DecompilerTextView.cs @@ -254,22 +254,32 @@ namespace ICSharpCode.ILSpy.TextView { Debug.WriteLine("Start decompilation of {0} tree nodes", context.TreeNodes.Length); + TaskCompletionSource tcs = new TaskCompletionSource(); if (context.TreeNodes.Length == 0) { // If there's nothing to be decompiled, don't bother starting up a thread. // (Improves perf in some cases since we don't have to wait for the thread-pool to accept our task) - TaskCompletionSource tcs = new TaskCompletionSource(); tcs.SetResult(new AvalonEditTextOutput()); return tcs.Task; } - return Task.Factory.StartNew( + Thread thread = new Thread(new ThreadStart( delegate { - AvalonEditTextOutput textOutput = new AvalonEditTextOutput(); - textOutput.LengthLimit = outputLengthLimit; - DecompileNodes(context, textOutput); - textOutput.PrepareDocument(); - return textOutput; - }, TaskCreationOptions.LongRunning); + try { + AvalonEditTextOutput textOutput = new AvalonEditTextOutput(); + textOutput.LengthLimit = outputLengthLimit; + DecompileNodes(context, textOutput); + textOutput.PrepareDocument(); + tcs.SetResult(textOutput); + #if DEBUG + } catch (OperationCanceledException ex) { + #else + } catch (Exception ex) { + #endif + tcs.SetException(ex); + } + })); + thread.Start(); + return tcs.Task; } static void DecompileNodes(DecompilationContext context, ITextOutput textOutput)