I’m building an app in Visual C++ 2008 Express Edition, a Windows forms app, hence using Managed C++/CLI.
I’m new to this and need guidance on the following:
I have a function that basically reboots a HID interface device. I want to show a progress bar (kind of a dummy progress bar for about 30 seconds) that progresses every second to 30 counts. After this is over, I want the code after all this to execute.
I tried doing this with the System.Windows.Forms timer and it just executes the code right after the timer->Enabled = true event.
Here is some code if it helps:
private:System::Void hidReboot(System::Void) {
System::UInt16 res = 0;
//bring up form to display progress bar
res = SendRebootCmd();
if (res == true)
{
timer1->Enabled = true; //in this tick event..i have the progress bar stuff
//some other code here
}
}
So basically, where the comment says //some other code here, I want to do that only when the progress bar is done and the timer has counted up to 30 ticks (1 second tick increments – 30 seconds).
I’ve tried putting a while loop there, but I can’t use that as it hangs the UI thread, thus not raising the tick event of the timer.
Any suggestions, readings or tips would be greatly appreciated. Thanks!
You should not put any kind of wait into that function. Just start the timer and then exit the function.
Add the remainder of the function in the timer with a check that determines if the countdown has finished.