以下两种方法之间的主要区别是什么:
ThreadPool.QueueUserWorkItem
Clients objClient = new Clients();
List<Clients> objClientList = Clients.GetClientList();
foreach (var list in objClientList)
{
ThreadPool.QueueUserWorkItem(new WaitCallback(SendFilesToClient), list);
}
Run Code Online (Sandbox Code Playgroud)
System.Threading.Tasks.Parallel ForEach
Clients objClient = new Clients();
List<Clients> objClientList = Clients.GetClientList();
Parallel.ForEach<Clients>(objClientList, list =>
{
SendFilesToClient(list);
});
Run Code Online (Sandbox Code Playgroud)
我是多线程新手,想知道在每种情况下会发生什么(在执行过程方面)每种方法的多线程水平是多少?帮助我想象这两个过程.
SendFilesToClient:从数据库获取数据,转换为Excel并将Excel文件发送到相应的客户端.
谢谢!
c# multithreading windows-services queueuserworkitem parallel.foreach
用于使用ThreadPool.QueueUserWorkItem (WaitCallback, Object)我的目标方法和数据启动一个线程.我可以将多个数据传递给我的方法吗?第二个参数QueueUserWorkItem (WaitCallback, Object)可以是数组吗?
我有一个Windows服务,我在使用Threadpool.QueueUserWorkItem.该服务连接到多个客户端数据库,抓取数据,转换为XLS并将文件发送到相应的FTP.
关于以下代码我有3个问题:
码:
private static System.Timers.Timer aTimer = new System.Timers.Timer(50000);
public void OnStart(string[] args)
{
CLE.WriteToEventLog("Service Started");
try
{
aTimer.Elapsed += new ElapsedEventHandler(PerformTimerOperation);
aTimer.Enabled = true;
}
catch (Exception ex)
{
CLE.WriteToEventLog("Error Starting Service: " + ex.Message);
}
}
private void PerformTimerOperation(object source, ElapsedEventArgs e)
{
CLE.WriteToEventLog("Timer Operation Started");
Clients objClient = new Clients();
List<Clients> objClientList = Clients.GetClientList();
foreach (var list in objClientList)
{
ThreadPool.QueueUserWorkItem(new WaitCallback(SendFilesToClient), list);
}
}
private void SendFilesToClient(Object stateInfo)
{
CLE.WriteToEventLog("Send Files To …Run Code Online (Sandbox Code Playgroud)