Skip to content

Commit

Permalink
Fix cancellation.
Browse files Browse the repository at this point in the history
  • Loading branch information
dgrunwald committed Feb 16, 2012
1 parent 43c80f9 commit ba80bb0
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 12 deletions.
2 changes: 1 addition & 1 deletion ILSpy.BamlDecompiler/BamlResourceEntryNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public override bool View(DecompilerTextView textView)
output.Write(ex.ToString());
}
return output;
}),
}, token),
t => textView.ShowNode(t.Result, this, highlighting)
);
return true;
Expand Down
2 changes: 1 addition & 1 deletion ILSpy/Commands/DecompileAllCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public override void Execute(object parameter)
}
});
return output;
}), task => MainWindow.Instance.TextView.ShowText(task.Result));
}, ct), task => MainWindow.Instance.TextView.ShowText(task.Result));
}
}
}
Expand Down
26 changes: 18 additions & 8 deletions ILSpy/TextView/DecompilerTextView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,13 @@ public void RunWithCancellation<T>(Func<CancellationToken, Task<T>> taskCreation
if (currentCancellationTokenSource == myCancellationTokenSource) {
currentCancellationTokenSource = null;
waitAdorner.Visibility = Visibility.Collapsed;
taskCompleted(task);
if (task.IsCanceled) {
AvalonEditTextOutput output = new AvalonEditTextOutput();
output.WriteLine("The operation was canceled.");
ShowOutput(output);
} else {
taskCompleted(task);
}
} else {
try {
task.Wait();
Expand Down Expand Up @@ -480,8 +486,8 @@ void UpdateDebugUI(bool isDecompilationOk)
if (DebugInformation.CodeMappings == null || !DebugInformation.CodeMappings.ContainsKey(token))
return;

if (!DebugInformation.CodeMappings[token].GetInstructionByTokenAndOffset(ilOffset, out member, out line))
return;
if (!DebugInformation.CodeMappings[token].GetInstructionByTokenAndOffset(ilOffset, out member, out line))
return;

// update marker
DebuggerService.JumpToCurrentLine(member, line, 0, line, 0, ilOffset);
Expand Down Expand Up @@ -520,10 +526,12 @@ Task<AvalonEditTextOutput> DecompileAsync(DecompilationContext context, int outp
DecompileNodes(context, textOutput);
textOutput.PrepareDocument();
tcs.SetResult(textOutput);
} catch (AggregateException ex) {
} catch (OutputLengthExceededException ex) {
tcs.SetException(ex);
} catch (OperationCanceledException ex) {
} catch (AggregateException ex) {
tcs.SetException(ex);
} catch (OperationCanceledException) {
tcs.SetCanceled();
}
} else
#endif
Expand All @@ -534,6 +542,8 @@ Task<AvalonEditTextOutput> DecompileAsync(DecompilationContext context, int outp
DecompileNodes(context, textOutput);
textOutput.PrepareDocument();
tcs.SetResult(textOutput);
} catch (OperationCanceledException) {
tcs.SetCanceled();
} catch (Exception ex) {
tcs.SetException(ex);
}
Expand Down Expand Up @@ -586,7 +596,7 @@ void WriteOutputLengthExceededMessage(ISmartTextOutput output, DecompilationCont
output.WriteLine();
}
#endregion

#region JumpToReference
/// <summary>
/// Jumps to the definition referred to by the <see cref="ReferenceSegment"/>.
Expand Down Expand Up @@ -717,9 +727,9 @@ Task<AvalonEditTextOutput> SaveToDiskAsync(DecompilationContext context, string
output.AddButton(null, "Open Explorer", delegate { Process.Start("explorer", "/select,\"" + fileName + "\""); });
output.WriteLine();
tcs.SetResult(output);
#if DEBUG
} catch (OperationCanceledException ex) {
tcs.SetException(ex);
tcs.SetCanceled();
#if DEBUG
} catch (AggregateException ex) {
tcs.SetException(ex);
#else
Expand Down
2 changes: 1 addition & 1 deletion ILSpy/TreeNodes/ResourceNodes/XamlResourceNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public override bool View(DecompilerTextView textView)
output.Write(ex.ToString());
}
return output;
}),
}, token),
t => textView.ShowNode(t.Result, this, highlighting)
);
return true;
Expand Down
2 changes: 1 addition & 1 deletion ILSpy/TreeNodes/ResourceNodes/XmlResourceNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public override bool View(DecompilerTextView textView)
output.Write(ex.ToString());
}
return output;
}),
}, token),
t => textView.ShowNode(t.Result, this, highlighting)
);
return true;
Expand Down

0 comments on commit ba80bb0

Please sign in to comment.