Asynchronous Delegates Vs Thread/ThreadPool?

前端 未结 8 2208
醉梦人生
醉梦人生 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:42

    I don't understand in .net why we have Asychronous calling (delegate.BeginInvoke() & delegate.EndInvoke()) as well as Thread class?

    • Asychronous calling is used when you have work items that should be handled in the background and you care when they finish.

    • Thread pools are for when you have work items that should be handled in the background and you don't care when they finish.

    • Threads are for doing stuff that never finishes.

    Examples:

    If you are reading a large file from disk and don't want to block the GUI thread, use an async call.

    If you are lazily writing one or more files in the background, use a thread pool.

    If you are polling the file system every few seconds looking for stuff that changed, use a thread.

提交回复
热议问题