Create a Timer and display Error Message once when time's out in C# -
i want create timer of 20 seconds. when reaches 20 second, pop out error message ok button. after user click ok, close whole application , exit completely.
my code follows. however, error message pop out continuously 5 times within 5 seconds.
how make error message displayed once instead of 5 times?
private void settimerusbport() { // create timer 20 second interval. atimer = new system.timers.timer(20000); //timer in ms atimer.interval = 20000; // hook elapsed event timer. atimer.elapsed += ontimedevent; atimer.enabled = true; } private void ontimedevent(object source, elapsedeventargs e) { dialogresult result; bool display; display = true; // check if usb port driver found, progress bar reached max if (detectcommport.isusbportpresent == true) { buttonautodetectingnext.enabled = true; atimer.stop(); atimer.enabled = false; } //if usb port driver not setup , reach 3 minutes: else { atimer.stop(); atimer.enabled = false; buttonautodetectingnext.enabled = false; this.timerprogressbar.enabled = false; if (display == true) { display = false; if (messagebox.show("a problem detected when attempting configure usb port. \n" + "please exit setup , reinstall bpro usb drivers. \n can rerun setup process.\n", "", messageboxbuttons.ok) == dialogresult.ok) { // exit application. close down. application.exit(); return; } } } }
thank help.
cheers, pf
Comments
Post a Comment