patrickc3000
Programmer
I have some code that basically copies from one directory into another, hides a winform, and shows the next form in the wizard. Sometimes it fails to execute the hide function, but if I physcially move the form, the next form is behind it. If I attempt to perform the same event a second time, it will behave as desired. Here is the code:
If I put a statement that I don't care if it gets executed or not after the return from the called function, like "string waitString = "wasting time";" it will execute the this.hide() statement every time. But, that is ugly and I want to understand what is going on.
private void btnNext_Click(object sender, EventArgs e)
{
if (!_destinationFolder.Contains(_catalogName))
_destinationFolder += "\\" + _catalogName;
//Check to see if the directory exists
if (Program.CheckDirectory(_destinationFolder))
{
//The catalog already exists in the directory, ask the user if they wish to overwrite it.
DialogResult result = MessageBox.Show("Do you want to overwrite the existing catalog folder in " + Program.IcatDataPath + "?","Overwrite", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
if (result == DialogResult.Cancel)
{
//Do not overwrite
return;
}
else
{
//overwrite
Cursor.Current = Cursors.WaitCursor;
Program.CopyDirectory(_selectedFolder, _destinationFolder);
//pause for processing
System.Threading.Thread.Sleep(5000);
Cursor.Current = Cursors.Default;
//optional code that will make sure this.Hide() gets called.
string waitString = "wasting time";
[/color green]
//This is the code that doesn’t get executed sometimes. [/color red]
this.Hide();
//This code always gets executed.[/color red]
_genesisPropertiesForm.Activate();
_genesisPropertiesForm.Show();
}
}
If I put a statement that I don't care if it gets executed or not after the return from the called function, like "string waitString = "wasting time";" it will execute the this.hide() statement every time. But, that is ugly and I want to understand what is going on.
private void btnNext_Click(object sender, EventArgs e)
{
if (!_destinationFolder.Contains(_catalogName))
_destinationFolder += "\\" + _catalogName;
//Check to see if the directory exists
if (Program.CheckDirectory(_destinationFolder))
{
//The catalog already exists in the directory, ask the user if they wish to overwrite it.
DialogResult result = MessageBox.Show("Do you want to overwrite the existing catalog folder in " + Program.IcatDataPath + "?","Overwrite", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
if (result == DialogResult.Cancel)
{
//Do not overwrite
return;
}
else
{
//overwrite
Cursor.Current = Cursors.WaitCursor;
Program.CopyDirectory(_selectedFolder, _destinationFolder);
//pause for processing
System.Threading.Thread.Sleep(5000);
Cursor.Current = Cursors.Default;
//optional code that will make sure this.Hide() gets called.
string waitString = "wasting time";
[/color green]
//This is the code that doesn’t get executed sometimes. [/color red]
this.Hide();
//This code always gets executed.[/color red]
_genesisPropertiesForm.Activate();
_genesisPropertiesForm.Show();
}
}