Browse Source

SDTraceListener: Don't pump messages while showing the assertion dialog.

pull/494/head
Daniel Grunwald 11 years ago
parent
commit
797b2760f0
  1. 45
      src/Main/SharpDevelop/Logging/SDTraceListener.cs

45
src/Main/SharpDevelop/Logging/SDTraceListener.cs

@ -62,47 +62,34 @@ namespace ICSharpCode.SharpDevelop.Logging
} }
if (!dialogIsOpen.Set()) if (!dialogIsOpen.Set())
return; return;
if (!SD.MainThread.InvokeRequired) { // We might be unable to display a dialog here, e.g. because
// Use a dispatcher frame that immediately exits after it is pushed // we're on the UI thread but dispatcher processing is disabled.
// to detect whether dispatcher processing is suspended. // In any case, we don't want to pump messages while the dialog is displaying,
DispatcherFrame frame = new DispatcherFrame(); // so we create a separate UI thread for the dialog:
frame.Continue = false; bool debug = false;
try { var thread = new Thread(() => ShowAssertionDialog(message, detailMessage, stackTrace, ref debug));
Dispatcher.PushFrame(frame); thread.SetApartmentState(ApartmentState.STA);
} catch (InvalidOperationException) { thread.Start();
// Dispatcher processing is suspended. thread.Join();
// We currently can't show dialogs on the UI thread; so use a new thread instead. if (debug)
new Thread(() => ShowAssertionDialog(message, detailMessage, stackTrace, false)).Start(); Debugger.Break();
return;
}
}
ShowAssertionDialog(message, detailMessage, stackTrace, true);
} }
void ShowAssertionDialog(string message, string detailMessage, string stackTrace, bool canDebug) void ShowAssertionDialog(string message, string detailMessage, string stackTrace, ref bool debug)
{ {
message = message + Environment.NewLine + detailMessage + Environment.NewLine + stackTrace; message = message + Environment.NewLine + detailMessage + Environment.NewLine + stackTrace;
List<string> buttonTexts = new List<string> { "Show Stacktrace", "Debug", "Ignore", "Ignore All" }; string[] buttonTexts = { "Show Stacktrace", "Debug", "Ignore", "Ignore All" };
if (!canDebug) { CustomDialog inputBox = new CustomDialog("Assertion Failed", message.TakeStartEllipsis(750), -1, 2, buttonTexts);
buttonTexts.RemoveAt(1);
}
CustomDialog inputBox = new CustomDialog("Assertion Failed", message.TakeStartEllipsis(750), -1, 2, buttonTexts.ToArray());
try { try {
while (true) { // show the dialog repeatedly until an option other than 'Show Stacktrace' is selected while (true) { // show the dialog repeatedly until an option other than 'Show Stacktrace' is selected
if (SD.MainThread.InvokeRequired) { inputBox.ShowDialog();
inputBox.ShowDialog();
} else {
inputBox.ShowDialog(SD.WinForms.MainWin32Window);
}
int result = inputBox.Result; int result = inputBox.Result;
if (!canDebug && result >= 1)
result++;
switch (result) { switch (result) {
case 0: case 0:
ExceptionBox.ShowErrorBox(null, message); ExceptionBox.ShowErrorBox(null, message);
break; // show the custom dialog again break; // show the custom dialog again
case 1: case 1:
Debugger.Break(); debug = true;
return; return;
case 2: case 2:
return; return;

Loading…
Cancel
Save