如何使许多按钮并行工作? [英] How to make many buttons work in parallel?

查看:92
本文介绍了如何使许多按钮并行工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用C#开发Windows应用程序,我需要通过USB与微控制器进行通信.该应用程序有一个按钮,可通过USB将代码发送到微控制器,一个按钮将微控制器暂停运行,而另一个则指示微控制器停止正在执行的操作.
当我按下发送按钮时,它可以正常工作,问题是在运行时单击其他按钮不会执行任何操作,因为发送按钮仅在完成所有代码后才会释放其他按钮的运行状态.你的身体.我需要在发送按钮运行时暂停和停止按钮也能正常工作.
我认为我可以使用线程来做到这一点,但是我对线程知之甚少.有人知道我怎么做吗?

在此先谢谢您.

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.

推荐答案

问题是(可能是,没有看到您的代码,这主要是猜测)您的按钮处理程序无法尽快完成-因此, UI任务在执行之前不会做任何事情,例如响应鼠标事件.您唯一真正的选择是使用线程并将处理代码完全移出UI.您可以使用 BackgroundWorker [
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.


这篇关于如何使许多按钮并行工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆