Asynchronous Delegates Vs Thread/ThreadPool?

前端 未结 8 2138
醉梦人生
醉梦人生 2020-12-22 23:57

I need to execute 3 parallel tasks and after completion of each task they should call the same function which prints out the results.

I don\'t understand in .net why

相关标签:
8条回答
  • 2020-12-23 00:47

    This is a long forgotten thread, but something that wasn't mentioned here at all was that there are two type of work, Compute and I/O bound.

    In the case of Compute bound work, this is executed in a separate thread (if you use BackgroundWorker or Begin/End pattern, this comes from the Thread pool; or, a custom thread if you decided to create your own thread).

    I/O bound on the other hand is executed in I/O ports (hardware support), and do not require a thread; File access and Network sockets are two examples of I/O bound tasks.

    0 讨论(0)
  • 2020-12-23 00:49

    If you have a long running process (e.g. a form application, IIS, Web Service, Windows Service) you will likely be better off using the Async methods. Threads require system resources and overhead. I always try to avoid creating threads. If I can't, I try to rely on ThreadPool to handle/manage them.

    You might get more applicable info if you can tell us what your application is.

    BeginInvoke uses a delegate behind the scenes where as the Async methods usually don't.

    0 讨论(0)
提交回复
热议问题