queueuserworkitem

How to use Threadpool.QueueUserWorkItem in a windows service?

不打扰是莪最后的温柔 提交于 2020-01-15 06:17:07
问题 I have a windows service where I am using Threadpool.QueueUserWorkItem. The service connects to multiple client databases, grabs data, converts to XLS and send files to the corresponding FTP. I have 3 questions regarding the code below: Am I using the Threadpool.QueueUserWorkItem correctly? Do I need to use Lock anywhere in the code to avoid issues? If yes, where and to what object. Is there anything that is not correct in the code? If yes, what and how to deal with it? Code: private static

How to use Threadpool.QueueUserWorkItem in a windows service?

心不动则不痛 提交于 2020-01-15 06:16:58
问题 I have a windows service where I am using Threadpool.QueueUserWorkItem. The service connects to multiple client databases, grabs data, converts to XLS and send files to the corresponding FTP. I have 3 questions regarding the code below: Am I using the Threadpool.QueueUserWorkItem correctly? Do I need to use Lock anywhere in the code to avoid issues? If yes, where and to what object. Is there anything that is not correct in the code? If yes, what and how to deal with it? Code: private static

How does one call into COM from worker thread created with NT's QueueUserWorkItem?

末鹿安然 提交于 2019-12-11 12:25:54
问题 I've got a set of tasks that I slaved to the NT threadpool using QueueUserWorkItem . I need to make some calls to COM from these separate threads to access data inside WMI. I'm unsure, however, how the correct calls to CoInitializeEx need to be made. Basically, the CoInitializeEx docs say that the call should be made once per thread. But I don't own these threads—NT does. I don't know when they get created or destroyed, or anything of that nature. Do I basically call ::CoInitializeEx() (with

Difference between ThreadPool.QueueUserWorkItem and Parallel.ForEach?

随声附和 提交于 2019-12-04 15:37:33
问题 What is the main difference between two of following approaches: ThreadPool.QueueUserWorkItem Clients objClient = new Clients(); List<Clients> objClientList = Clients.GetClientList(); foreach (var list in objClientList) { ThreadPool.QueueUserWorkItem(new WaitCallback(SendFilesToClient), list); } System.Threading.Tasks.Parallel ForEach Clients objClient = new Clients(); List<Clients> objClientList = Clients.GetClientList(); Parallel.ForEach<Clients>(objClientList, list => { SendFilesToClient

Difference between ThreadPool.QueueUserWorkItem and Parallel.ForEach?

雨燕双飞 提交于 2019-12-03 09:43:44
What is the main difference between two of following approaches: ThreadPool.QueueUserWorkItem Clients objClient = new Clients(); List<Clients> objClientList = Clients.GetClientList(); foreach (var list in objClientList) { ThreadPool.QueueUserWorkItem(new WaitCallback(SendFilesToClient), list); } System.Threading.Tasks.Parallel ForEach Clients objClient = new Clients(); List<Clients> objClientList = Clients.GetClientList(); Parallel.ForEach<Clients>(objClientList, list => { SendFilesToClient(list); }); I am new to multi-threading and want to know what's going to happen in each case (in terms of