Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/multithreading/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Multithreading 如何使线程等待事件发生并在ThreadPool.QueueUserWorkItem中继续其进程 public void CommandTypeProcess(列表列表、命令\u Do ObjCommand\u Do) { log.Info(“[”+DateTime.Now+”]“+”:AddressTypeSplit类处理不同线程中的每个单元”); var numThreads=50; var toProcess=numThreads; var resetEvent=新的手动重置事件(false); //ObjCommand_Do=ObjGetMsgnumertorAndIMEIno.unitiemmsgnumerator(ObjCommand_Do); //ObjCommand_Do.Msgnumerator=ObjCommand_Do.Msgnumerator-1; //ObjCommand_Do.MsgnumeratorStart=ObjCommand_Do.Msgnumerator; foreach(ObjCommand_Do.ListNumberOfunit中的字符串单位) { if(单位!=常量.NullValue) { log.Info(“[”+DateTime.Now+”]“+”线程为单元“+Unit”启动); ThreadPool.QueueUserWorkItem(新的WaitCallback(委托)(对象状态) { //CommandProcessThread.CommandProcessFunction(ObjCommand_Do,CommandPacket,CommandType,AddressUnitNumber,ObjCommand_Do.MsgnumeratorStart,ObjCommand_Do.MsgnumeratorEnd,AddressID); InputOutputPacketProcess(ObjCommand_Do,list,unit); 如果(互锁.减量(ref-toProcess)==0)resetEvent.Set(); }),空); resetEvent.WaitOne(); } } }_Multithreading_Winforms_C# 3.0 - Fatal编程技术网

Multithreading 如何使线程等待事件发生并在ThreadPool.QueueUserWorkItem中继续其进程 public void CommandTypeProcess(列表列表、命令\u Do ObjCommand\u Do) { log.Info(“[”+DateTime.Now+”]“+”:AddressTypeSplit类处理不同线程中的每个单元”); var numThreads=50; var toProcess=numThreads; var resetEvent=新的手动重置事件(false); //ObjCommand_Do=ObjGetMsgnumertorAndIMEIno.unitiemmsgnumerator(ObjCommand_Do); //ObjCommand_Do.Msgnumerator=ObjCommand_Do.Msgnumerator-1; //ObjCommand_Do.MsgnumeratorStart=ObjCommand_Do.Msgnumerator; foreach(ObjCommand_Do.ListNumberOfunit中的字符串单位) { if(单位!=常量.NullValue) { log.Info(“[”+DateTime.Now+”]“+”线程为单元“+Unit”启动); ThreadPool.QueueUserWorkItem(新的WaitCallback(委托)(对象状态) { //CommandProcessThread.CommandProcessFunction(ObjCommand_Do,CommandPacket,CommandType,AddressUnitNumber,ObjCommand_Do.MsgnumeratorStart,ObjCommand_Do.MsgnumeratorEnd,AddressID); InputOutputPacketProcess(ObjCommand_Do,list,unit); 如果(互锁.减量(ref-toProcess)==0)resetEvent.Set(); }),空); resetEvent.WaitOne(); } } }

Multithreading 如何使线程等待事件发生并在ThreadPool.QueueUserWorkItem中继续其进程 public void CommandTypeProcess(列表列表、命令\u Do ObjCommand\u Do) { log.Info(“[”+DateTime.Now+”]“+”:AddressTypeSplit类处理不同线程中的每个单元”); var numThreads=50; var toProcess=numThreads; var resetEvent=新的手动重置事件(false); //ObjCommand_Do=ObjGetMsgnumertorAndIMEIno.unitiemmsgnumerator(ObjCommand_Do); //ObjCommand_Do.Msgnumerator=ObjCommand_Do.Msgnumerator-1; //ObjCommand_Do.MsgnumeratorStart=ObjCommand_Do.Msgnumerator; foreach(ObjCommand_Do.ListNumberOfunit中的字符串单位) { if(单位!=常量.NullValue) { log.Info(“[”+DateTime.Now+”]“+”线程为单元“+Unit”启动); ThreadPool.QueueUserWorkItem(新的WaitCallback(委托)(对象状态) { //CommandProcessThread.CommandProcessFunction(ObjCommand_Do,CommandPacket,CommandType,AddressUnitNumber,ObjCommand_Do.MsgnumeratorStart,ObjCommand_Do.MsgnumeratorEnd,AddressID); InputOutputPacketProcess(ObjCommand_Do,list,unit); 如果(互锁.减量(ref-toProcess)==0)resetEvent.Set(); }),空); resetEvent.WaitOne(); } } },multithreading,winforms,c#-3.0,Multithreading,Winforms,C# 3.0,在上述方法中,我为每个单元使用Threadpool.QueueUserWorkItem。 每当线程池中的任何新线程启动时,都应等待事件发生,如果事件发生,则应继续处理。哪个部分不工作?上面的代码正在工作。它为我传入InputOutputPacketProcess方法的每个单元创建新线程。但我希望线程池中的每个线程在启动后等待,对于要发生的事件,如果事件发生,则它应在同一线程中继续进程。如果启动线程,则需要等待信号继续,为什么在收到信号后不能启动线程?至少可以在线程内保存一些线程(系统资源)。我会

在上述方法中,我为每个单元使用Threadpool.QueueUserWorkItem。
每当线程池中的任何新线程启动时,都应等待事件发生,如果事件发生,则应继续处理。

哪个部分不工作?上面的代码正在工作。它为我传入InputOutputPacketProcess方法的每个单元创建新线程。但我希望线程池中的每个线程在启动后等待,对于要发生的事件,如果事件发生,则它应在同一线程中继续进程。如果启动线程,则需要等待信号继续,为什么在收到信号后不能启动线程?至少可以在线程内保存一些线程(系统资源)。我会将数据包发送到特定的单元。在这种情况下,单元有时会脱机或断开连接,我不想松开线程。Uisng事件我想检查设备是否联机或再次连接。如果是这样,它将再次连接,那么我将继续在同一线程中向同一设备发送数据包。
public void CommandTypeProcess(List<XMLIdentifier> list, Command_Do ObjCommand_Do)   
{
    log.Info("[" + DateTime.Now + "]" + ":AddressTypeSplit class to process each unit in different thread");
    var numThreads = 50;
    var toProcess = numThreads;
    var resetEvent = new ManualResetEvent(false);
    //ObjCommand_Do = ObjGetMsgnumertorAndIMEIno.UnitIEMIMsgnumerator(ObjCommand_Do);
    //ObjCommand_Do.Msgnumerator = ObjCommand_Do.Msgnumerator - 1;
    //ObjCommand_Do.MsgnumeratorStart = ObjCommand_Do.Msgnumerator;
    foreach(string unit in ObjCommand_Do.ListNumberOfunit)
    {         
        if(unit!=Constant.NullValue)
        {
            log.Info("[" + DateTime.Now + "]" + "Thread is started for Unit"+unit);
           ThreadPool.QueueUserWorkItem(new WaitCallback(delegate(object state)
            {
               // ObjCommandProcessThread.CommandProcessFunction(ObjCommand_Do,CommandPacket, CommandType, AddressUnitNumber,ObjCommand_Do.MsgnumeratorStart,ObjCommand_Do.MsgnumeratorEnd,AddressID);
                ObjUnitDataPacketProcess.InputOutputPacketProcess(ObjCommand_Do, list,unit);
                if (Interlocked.Decrement(ref toProcess) == 0) resetEvent.Set();
            }), null);
            resetEvent.WaitOne();
        }
    }
}