At the click of a button I check to see if an excel is open, if it is a message pops up to close it - once closed the following code is called:
1. Record all excel process IDs in a hashtable;
2. Export data to an excel spreadsheet;
3. Kill any excel processes that do not exist in the hashtable.
At the start of the Export Data to excel spreadsheet I have the following code:
That kind of tells me that the code has reached this point, as the button changes colour, almost instantly, and the text changes from Create Output to Working.
However, if you have the spreadsheet open, and you are told to close it. - after closing it...the time between the button changing and the dialog box opening is like 10 secs....if you do not have the excel open when you click output, the time is like a nano second.
The next line is simply:
It is the dialog box which just seems to take an age to display.
I tried a break point to see if it was going off to do something....but it isn't, it just hangs there for a long time.
Are there any tips on working out why there is such a delay, which might lead to a fix?
Below is the whole IF statement, just in case the way I have nested it is causing a problem.. It is the first DialogResult that is slow - once that fires, the rest first just fine with no delays.
1. Record all excel process IDs in a hashtable;
2. Export data to an excel spreadsheet;
3. Kill any excel processes that do not exist in the hashtable.
At the start of the Export Data to excel spreadsheet I have the following code:
C#:
OutPut.Text = "WORKING";
OutPut.BackColor = Color.DarkGreen;
That kind of tells me that the code has reached this point, as the button changes colour, almost instantly, and the text changes from Create Output to Working.
However, if you have the spreadsheet open, and you are told to close it. - after closing it...the time between the button changing and the dialog box opening is like 10 secs....if you do not have the excel open when you click output, the time is like a nano second.
The next line is simply:
C#:
if (File.Exists(ctk1.EX1))
{
DialogResult dialogResult = MessageBox.Show
($"This will delete { ctk1.EX1 } are you sure?", "Delete Excel", MessageBoxButtons.YesNo);
It is the dialog box which just seems to take an age to display.
I tried a break point to see if it was going off to do something....but it isn't, it just hangs there for a long time.
Are there any tips on working out why there is such a delay, which might lead to a fix?
Below is the whole IF statement, just in case the way I have nested it is causing a problem.. It is the first DialogResult that is slow - once that fires, the rest first just fine with no delays.
C#:
if (OutPut.Text == "CREATE OUTPUT")
{
OutPut.Text = "WORKING";
OutPut.BackColor = Color.DarkGreen;
if (File.Exists(ctk1.EX1))
{
DialogResult dialogResult = MessageBox.Show($"This will delete { ctk1.EX1 }, are you sure?", "Delete Excel", MessageBoxButtons.YesNo);
if (dialogResult == DialogResult.Yes)
{
File.Delete(ctk1.EX1);
MessageBox.Show("Daily Log Deleted");
}
else if (dialogResult == DialogResult.No)
{
OutPut.Text = "CREATE OUTPUT";
OutPut.BackColor = Color.Maroon;
return;
}
}
else
{
}