我将如何实现基于事件的异步模式?

发布于 2024-10-03 07:38:16 字数 417 浏览 1 评论 0 原文

您好,我想使用 C# 实现基于事件的异步模式。下面的 Microsoft 文档确实很有帮助,但它忽略了实现细节,这是正确的。

http://msdn.microsoft.com/en-us/library/ms228969.aspx

实现此模式有哪些选择?我应该使用 Delegate.BeginInvoke、ThreadPool.QueueUserWorkItem、new Thread()、BackgroundWorker 类还是其他类?

我正在创建一个简单的代码库。它应该可以在 Windows 窗体、控制台应用程序或 ASP.NET 上下文中使用。

很高兴看到一些示例代码。

Hi I want to implement the event-based asynchronous pattern using c#. The Microsoft documentation below is really helpful but quite rightly it leaves out the implementation details.

http://msdn.microsoft.com/en-us/library/ms228969.aspx

What are my options for implementing this pattern? Should I use the Delegate.BeginInvoke, ThreadPool.QueueUserWorkItem, new Thread(), BackgroundWorker class, or something else?

I'm creating a simple code library. It should be usable in a Windows form, console app, or ASP.NET context.

It would be great to see some sample code.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦里寻她 2024-10-10 07:38:16

如果您想实现基于事件的异步模式,则 AsyncFunc 是最简单的方法。

它极大地简化了这种模式。您无需担心 ThreadPoolsThreadsBackgroundWorkers。 AsyncFunc 会为您处理一切。此外,这种方法允许您将业务逻辑与特定于模式的实现分开,从而提高可测试性。

If you want to implement Event-Based Asynchronous Pattern then AsyncFunc is the easiest way to go.

It simplifies this patter dramatically. You don't need to bother about ThreadPools, Threads or BackgroundWorkers. AsyncFunc handles everything for you. Moreover, this approach allows you to separate your business logic from pattern specific implementation which improves testability.

望她远 2024-10-10 07:38:16

阅读该文章的这一部分:

http://msdn.microsoft.com/en- us/library/9hk12d4y.aspx

话虽这么说,我建议您应该使用的技术取决于您的应用程序,因此没有更多关于这些异步操作将执行的操作以及调用它们的频率和频率的详细信息它们被称为什么情况,我无法就您的情况给出最佳使用技术的建议。

Read this section of that article:

http://msdn.microsoft.com/en-us/library/9hk12d4y.aspx

That being said, I would suggest that the technique you should use depends on your application, so without more details about what these async operations will be doing and how often they will be called and in what circumstances they are called, I can't give a recommendation on what the best technique to use is in your situation.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文