简体   繁体   中英

Buttons not enabling/disabling

My program runs a test over a serial connection. After I click the RUN TEST button everything works great. The RUN TEST button disappears and the STOP button pops up. Data collection runs as expected. My problem is that the STOP button doesn't respond. All of my testing code is run under the RUN TEST button click event. Is this uninterruptible by my second button?

Note: I use the whateverButton.enable and whateverButton.visible properties. Is there another one I need to set to get this to work?

runButton.Enabled = false;
runButton.Visible = false;
STOPbutton.Enabled = true;
STOPbutton.Visible = true;

The rest of the program is to big to fully include.

Any help with this would greatly appreciated.

Let me guess - you disable the "Run", enable the "Stop", perform your task, reverse the enable/disable on "Run" and "Stop"?

Your issue is that the UI is not updated because the UI thread is busy running your task.

Use BackgroundWorker or Task.Run to spawn a new thread for the task, some significant refactoring may need to happen to take UI interaction out of the background thread and to support cancelling.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM