事件在 C# 中是同步的。我有这个应用程序,其中我的主窗体启动一个线程,其中有一个循环监听流。当流中出现某些事件时,就会从循环中向主窗体触发一个事件。
如果主窗体运行缓慢或显示消息框或其他内容,循环将被暂停。解决这个问题的最佳方法是什么?通过在主窗体上使用回调和调用?
最佳答案
由于您使用的是表单,因此更简单的方法是使用 BackgroundWorker组件。
The BackgroundWorker class allows you to run an operation on a separate, dedicated thread. Time-consuming operations like downloads and database transactions can cause your user interface (UI) to seem as though it has stopped responding while they are running. When you want a responsive UI and you are faced with long delays associated with such operations, the BackgroundWorker class provides a convenient solution.
关于c# - 在 C# 中使事件异步的最佳方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/80645/