My application is a C# Windows form application. When the user presses the button “Generate” my application creates a new thread and run the new process the process goes something like this pseudo code below
Loop counter = 1 to N
progressbar = counter/N
Display msg on label1
Do some tasks
Loop
progressbar = 100%
Display msg on lable1
I’ve delegate my processbar and label msgs, the messages shows up when it’s within the loop with no problem I’ve even added an event to run Application.DoEvents() whenever the label text changes , however my last msg NEVER shows up, I’ve tried placing Application.DoEvents() right after the last msg label, however no solution. Anyone else encounter this before?
Thanks for the help everyone!
Edit
this is how I coded my last msg (The one after the loop)
this.BeginInvoke((MethodInvoker)delegate()
{
toolStripProgressBar1.Value = 100;
btnCancel.Enabled = false;
btnBrowse.Enabled = true;
btnSaveTo.Enabled = true;
btnGenerate.Enabled = false;
// Performance testing
lblGeneratingInfo.Text = "Generation Complete! Total Run time: " + DateTime.Now.Subtract(startDate).ToString();
});
FIXED:
I’m assuming the text I tried to display was too long… when I replaced “Generating Complete: Total run time ” with just “Run time: ” it displayed o_o
You mention that this all happens on a new thread. However, you also mention
DoEvents. To me, that suggests that you are updating the UI from the worker thread, which would be a problem (the other possibility is that you are running on a worker thread, but blocking the UI thread, which is also a problem).You should be asking the UI to update itself on the UI thread – then you don’t need
DoEvents: