c# - 在 C# 中使事件异步的最佳方法

标签 c# events asynchronous

事件在 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/

相关文章:

c# - 算法 - 最小化总迟到

c# - 为什么这个字符串扩展方法没有抛出异常?

javascript - React onClick - 传递带有参数的事件

c# - 在 ASP.NET MVC 3 中添加你自己的 HtmlHelper

c# - 如何从 FluentValidation 获取验证规则

javascript - 加载函数 onclick

android - 如何管理 On App 退出事件并在应用关闭之前执行某些操作?

javascript - promise 所有异步操作

javascript - 减少来自客户端的第三方异步调用次数

javascript - 如何从异步调用返回响应?