Click here to Skip to main content
16,016,738 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I am developing a windows application in C# where I need to communicate with a microcontroller through the USB. This application has a button that sends code to the microcontroller through the USB, one that sends the microcontroller to pause which it is running and has another one that tells the microcontroller to stop what it was doing.
When I press the send button it works normally, the problem is that while it is running to click on other buttons do nothing, because the send button will only release the running for the other buttons after it has finished all the code that it has in your body. I need that the pause and stop buttons also work while the send button is running.
I think that I may be able to do this using threads, but I do not know much about threads. Does anyone know how I do it?

Thanks in advance.
Posted
Comments
BillWoodruff 17-Jan-12 21:04pm    
Does your micro-controller support any hardware interrupts ?
Edson Rodrigues da Silva 18-Jan-12 20:07pm    
My application does not interrupt the micro-controller, pause and stop buttons only send one line of code in which the micro-controller knows whether stop or pause the action that it is running.
Sergey Alexandrovich Kryukov 17-Jan-12 21:32pm    
If you don't know much, this is useless. Learn it. Look at your talking. Buttons do not work in parallel, processors, processor cores and threads do.
--SA

1 solution

The problem is (probably, without seeing your code it is mostly guesswork) that your button handler does not finish as quickly as possible - so the UI task does not get to do anything such as respond to a mouse event until it has. Your only real option there is to use a thread and move the processing code out of the UI completely. You could probably do this quite easily with a BackgroundWorker[^] - the link includes an example of starting and cancelling a thread.
 
Share this answer
 
Comments
Edson Rodrigues da Silva 17-Jan-12 14:51pm    
Thanks, I'll look at the link and try to use it in my application. If to appear doubts I'll post questions in the forum again.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900