Run code in Background Worker

不打扰是莪最后的温柔 提交于 2019-12-02 06:22:35

In general your question is a little to broad. Not sure if you mean the background worker class which is aviable in WinForms (your tag indicates you mean asp.net 5). Do you really want to use exact this class ?

But i would recommend you to use tasks. See MSDN Task Parallel Library

There you can create and await tasks.

   var result = await Task.Run(() => myBackgroundWork());

Furthermore if your background code supports async (e.g. network traffic) you could simplay await it and make your code asynchron without using threads.

See for example Doing Work without threads . Threads always come at a cost and you may not want to pay this.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!