1
0
mirror of https://github.com/fadden/6502bench.git synced 2024-06-13 14:29:30 +00:00

Add parent window to all MessageBox.Show() invocations

Every once in a while, SourceGen will become unresponsive when it
tries to show a MessageBox.  In the debugger you can see the GC
running frantically, but the stack trace is just sitting on the
MessageBox show call.  Apparently, if you don't specify a parent
window argument, the MessageBox will occasionally end up behind
everything else, and you can get stuck.

I'm not sure what the GC frenzy is about, or whether this will fix
what I'm seeing, but it's easy to do and might solve the problem.

cf. https://stackoverflow.com/q/3467403/294248
This commit is contained in:
Andy McFadden 2018-10-07 13:13:00 -07:00
parent 74037928ee
commit 360204a16d
6 changed files with 22 additions and 20 deletions

View File

@ -422,7 +422,7 @@ namespace SourceGen.AppForms {
}
string msg = string.Format(Properties.Resources.EXTERNAL_FILE_BAD_DIR,
RuntimeDataAccess.GetDirectory(), projDir, pathName);
MessageBox.Show(msg, Properties.Resources.EXTERNAL_FILE_BAD_DIR_CAPTION,
MessageBox.Show(this, msg, Properties.Resources.EXTERNAL_FILE_BAD_DIR_CAPTION,
MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
@ -540,7 +540,7 @@ namespace SourceGen.AppForms {
} else {
msg = string.Format(Properties.Resources.SYMBOL_IMPORT_GOOD, foundCount);
}
MessageBox.Show(msg, Properties.Resources.SYMBOL_IMPORT_CAPTION,
MessageBox.Show(this, msg, Properties.Resources.SYMBOL_IMPORT_CAPTION,
MessageBoxButtons.OK, MessageBoxIcon.Information);
}
@ -591,7 +591,7 @@ namespace SourceGen.AppForms {
}
string msg = string.Format(Properties.Resources.EXTERNAL_FILE_BAD_DIR,
RuntimeDataAccess.GetDirectory(), projDir, pathName);
MessageBox.Show(msg, Properties.Resources.EXTERNAL_FILE_BAD_DIR_CAPTION,
MessageBox.Show(this, msg, Properties.Resources.EXTERNAL_FILE_BAD_DIR_CAPTION,
MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}

View File

@ -196,7 +196,7 @@ namespace SourceGen.AppForms {
private void ProjectView_Load(object sender, EventArgs e) {
if (RuntimeDataAccess.GetDirectory() == null) {
MessageBox.Show(Properties.Resources.RUNTIME_DIR_NOT_FOUND,
MessageBox.Show(this, Properties.Resources.RUNTIME_DIR_NOT_FOUND,
Properties.Resources.RUNTIME_DIR_NOT_FOUND_CAPTION,
MessageBoxButtons.OK, MessageBoxIcon.Error);
Application.Exit();
@ -211,7 +211,7 @@ namespace SourceGen.AppForms {
}
string msg = string.Format(Properties.Resources.PLUGIN_DIR_FAIL,
pluginPath + ": " + ex.Message);
MessageBox.Show(msg, Properties.Resources.PLUGIN_DIR_FAIL_CAPTION,
MessageBox.Show(this, msg, Properties.Resources.PLUGIN_DIR_FAIL_CAPTION,
MessageBoxButtons.OK, MessageBoxIcon.Error);
Application.Exit();
return;
@ -751,7 +751,8 @@ namespace SourceGen.AppForms {
Debug.WriteLine("PrepareNewProject exception: " + ex);
string message = Properties.Resources.OPEN_DATA_FAIL_CAPTION;
string caption = Properties.Resources.OPEN_DATA_FAIL_MESSAGE + ": " + ex.Message;
MessageBox.Show(caption, message, MessageBoxButtons.OK, MessageBoxIcon.Error);
MessageBox.Show(this, caption, message, MessageBoxButtons.OK,
MessageBoxIcon.Error);
return false;
}
proj.UseMainAppDomainForPlugins = mUseMainAppDomainForPlugins;
@ -1284,7 +1285,7 @@ namespace SourceGen.AppForms {
if (!File.Exists(projPathName)) {
string msg = string.Format(Properties.Resources.ERR_FILE_NOT_FOUND, projPathName);
MessageBox.Show(msg, Properties.Resources.ERR_FILE_GENERIC_CAPTION,
MessageBox.Show(this, msg, Properties.Resources.ERR_FILE_GENERIC_CAPTION,
MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
@ -1473,7 +1474,8 @@ namespace SourceGen.AppForms {
private bool DoSave(string pathName) {
Debug.WriteLine("SAVING " + pathName);
if (!ProjectFile.SerializeToFile(mProject, pathName, out string errorMessage)) {
MessageBox.Show(Properties.Resources.ERR_PROJECT_SAVE_FAIL + ": " + errorMessage,
MessageBox.Show(this,
Properties.Resources.ERR_PROJECT_SAVE_FAIL + ": " + errorMessage,
Properties.Resources.OPERATION_FAILED,
MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
@ -1528,7 +1530,7 @@ namespace SourceGen.AppForms {
Debug.WriteLine("ProjectView.DoClose() - dirty=" +
(mProject == null ? "N/A" : mProject.IsDirty.ToString()));
if (mProject != null && mProject.IsDirty) {
DialogResult result = MessageBox.Show(Properties.Resources.UNSAVED_CHANGES,
DialogResult result = MessageBox.Show(this, Properties.Resources.UNSAVED_CHANGES,
Properties.Resources.UNSAVED_CHANGES_CAPTION, MessageBoxButtons.OKCancel,
MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2);
if (result == DialogResult.Cancel) {
@ -1583,7 +1585,7 @@ namespace SourceGen.AppForms {
// an explanation, or have some annoying click-through.
//
// This only appears for never-saved projects, not projects with unsaved data.
MessageBox.Show(Properties.Resources.SAVE_BEFORE_ASM_TEXT,
MessageBox.Show(this, Properties.Resources.SAVE_BEFORE_ASM_TEXT,
Properties.Resources.SAVE_BEFORE_ASM_CAPTION,
MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
@ -1824,7 +1826,7 @@ namespace SourceGen.AppForms {
}
// Announce that we've wrapped around, then clear the start index.
MessageBox.Show(Properties.Resources.FIND_REACHED_START,
MessageBox.Show(this, Properties.Resources.FIND_REACHED_START,
Properties.Resources.FIND_REACHED_START_CAPTION, MessageBoxButtons.OK,
MessageBoxIcon.Information);
mFindStartIndex = -1;
@ -4367,7 +4369,7 @@ namespace SourceGen.AppForms {
if (fi.Length > Tools.HexDumpViewer.MAX_LENGTH) {
string msg = string.Format(Properties.Resources.ERR_FILE_TOO_LARGE,
Tools.HexDumpViewer.MAX_LENGTH);
MessageBox.Show(msg, Properties.Resources.OPEN_DATA_FAIL_CAPTION,
MessageBox.Show(this, msg, Properties.Resources.OPEN_DATA_FAIL_CAPTION,
MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
@ -4375,7 +4377,7 @@ namespace SourceGen.AppForms {
try {
data = File.ReadAllBytes(fileName);
} catch (Exception ex) {
MessageBox.Show(ex.Message);
MessageBox.Show(this, ex.Message);
return;
}

View File

@ -107,7 +107,7 @@ namespace SourceGen.AsmGen {
DialogResult = DialogResult.Cancel;
} else if (e.Error != null) {
// Unexpected -- shell command execution shouldn't throw exceptions.
MessageBox.Show(e.Error.ToString(), Properties.Resources.OPERATION_FAILED,
MessageBox.Show(this, e.Error.ToString(), Properties.Resources.OPERATION_FAILED,
MessageBoxButtons.OK, MessageBoxIcon.Error);
DialogResult = DialogResult.Cancel;
} else {

View File

@ -366,7 +366,7 @@ namespace SourceGen.AsmGen {
if (results.ExitCode == 0) {
FileInfo fi = new FileInfo(results.OutputPathName);
if (!fi.Exists) {
MessageBox.Show(Properties.Resources.ASM_OUTPUT_NOT_FOUND,
MessageBox.Show(this, Properties.Resources.ASM_OUTPUT_NOT_FOUND,
Properties.Resources.ASM_MISMATCH_CAPTION,
MessageBoxButtons.OK, MessageBoxIcon.Error);
sb.Append(Properties.Resources.ASM_MATCH_FAILURE);
@ -377,13 +377,13 @@ namespace SourceGen.AsmGen {
// The files matched up to the point where one ended.
string msg = string.Format(Properties.Resources.ASM_MISMATCH_LENGTH_FMT,
fi.Length, mProject.FileData.Length);
MessageBox.Show(msg, Properties.Resources.ASM_MISMATCH_CAPTION,
MessageBox.Show(this, msg, Properties.Resources.ASM_MISMATCH_CAPTION,
MessageBoxButtons.OK, MessageBoxIcon.Error);
sb.Append(msg);
} else {
string msg = string.Format(Properties.Resources.ASM_MISMATCH_DATA_FMT,
offset, fileVal, mProject.FileData[offset]);
MessageBox.Show(msg, Properties.Resources.ASM_MISMATCH_CAPTION,
MessageBox.Show(this, msg, Properties.Resources.ASM_MISMATCH_CAPTION,
MessageBoxButtons.OK, MessageBoxIcon.Error);
sb.Append(msg);
}

View File

@ -99,7 +99,7 @@ namespace SourceGen.AsmGen {
} else if (e.Error != null) {
// This should only happen on a file I/O error, e.g. out of disk space or
// unable to overwrite an existing file.
MessageBox.Show(e.Error.ToString(), Properties.Resources.OPERATION_FAILED,
MessageBox.Show(this, e.Error.ToString(), Properties.Resources.OPERATION_FAILED,
MessageBoxButtons.OK, MessageBoxIcon.Error);
DialogResult = DialogResult.Cancel;
} else {
@ -108,7 +108,7 @@ namespace SourceGen.AsmGen {
if (Results == null || Results.Count == 0) {
// Shouldn't happen -- generator should have reported error.
MessageBox.Show("Internal error: no files generated",
MessageBox.Show(this, "Internal error: no files generated",
Properties.Resources.OPERATION_FAILED,
MessageBoxButtons.OK, MessageBoxIcon.Error);
} else {

View File

@ -178,7 +178,7 @@ namespace SourceGen.Setup {
if (fi.Length > DisasmProject.MAX_DATA_FILE_SIZE) {
string msg = string.Format(Properties.Resources.OPEN_DATA_TOO_LARGE,
fi.Length / 1024, DisasmProject.MAX_DATA_FILE_SIZE / 1024);
MessageBox.Show(msg, Properties.Resources.OPEN_DATA_FAIL_CAPTION,
MessageBox.Show(this, msg, Properties.Resources.OPEN_DATA_FAIL_CAPTION,
MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}