开发者

How would I go about implementing the event-based asynchronous pattern?

开发者 https://www.devze.com 2023-01-25 13:28 出处:网络
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.

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 ap开发者_如何学Cp, or ASP.NET context.

It would be great to see some sample code.


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 what improves testability.

http://asyncfunc.codeplex.com

You can find comparison of MSDN recommended way and AsyncFunc implementation of the same component:

MSDN vs. AsyncFunc


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号