c# - Creating X amount of threads that execute a task at the same time -


I'm trying to dynamically create the amount of Threads of X (specified by the user), then basically those Everyone has to execute some code at the same time within a 1 second interval.

The issue I am arriving is that the work I am trying to fulfill depends on the loop, to determine whether the current IP is equal to the last or not. (This scans the host) So as long as I loop inside it, it is shutting down and not making other threads, and not executing the code. I want to go all those at the same time, Waiting for one second (a timer or something that does not lock the thread since the code it was executed). Can somebody help me out? Here is my current code:

  int thread = convert. ToInt32 (txtThreads.Text); & Lt; Thread & gt; WorkerThreads = New list & lt; Thread & gt; (); String = from txtStart.Text, for = txtEnd.Text; UIT current = from.ToUInt (), final = to.ToUInt (); Inverted total = final - present; {Thread thread = new thread ((=); (for (int i = 0; i & lt; threads; i ++) {for (int t = 0; t & lt; convert. ToInt32 (total); t + = I) {while (current & lt; = final) {current = Convert.ToUInt32 (current + t); var ip = current.ToIPAddress (); doSomething (ip);}}}); workerThreads.Add (thread ); Thread.Start ();}  

Lambda as the body of your thread Do not use, otherwise I the value is not doing what you think is doing instead pass the value in a method.

At the same timeSomething similar happens to start all threads:

  Private objects syncObj = new object (); Zero Threadboard (Object Boxed) {Ultimate Parameters = (Ultimate) Boxing; Lock (syncObj } {Monitor.Wait (syncObj);} // Here works} Straight parameters {// passed value here} Zero Start initialThreads () {int threads = Convert.ToInt32 (txtThreads.Text); List of & lt; Thread & Gt; WorkerThreads = new list & lt; Thread & gt; (); String = from txtStart.Text, for = txtEnd.Text; UIT current = from.ToUInt (), final = to.ToUInt (); Inverted total = final - present; (Int i = 0; i & lt; threads; i ++) {thread thread = new thread (new parameterated feed start (this. Threadbowdie, new params, / / ​​initialize values ​​here)); WorkerThreads.Add (thread); Thread.Start (); } Lock (syncObj) {monitor. PulseAul (syncObj); }}  

Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

c# - MySQL Parameterized Select Query joining tables issue -