Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

wait for threadpool to complete with decrement

int toProcess = 10;
using(ManualResetEvent resetEvent = new ManualResetEvent(false))
{
    var list = new List<int>();
    for(int i=0;i<10;i++) list.Add(i); 
    for(int i=0;i<10;i++)
    {
        ThreadPool.QueueUserWorkItem(
           new WaitCallback(x => {
              Console.WriteLine(x);  
              // Safely decrement the counter
              if (Interlocked.Decrement(ref toProcess)==0)
                 resetEvent.Set();

           }),list[i]);
    } 

    resetEvent.WaitOne();
}
// When the code reaches here, the 10 threads will be done
Console.WriteLine("Done");
Comment

PREVIOUS NEXT
Code Example
Csharp :: how to add logo in a unity game apk 
Csharp :: c# string to control name 
Csharp :: unity editor window mesh field 
Csharp :: identity-1.us-south.iam.test.cloud.ibm.com:443 
Csharp :: c# compare char arrays 
Csharp :: unity rotatoin angle 
Csharp :: C# string go to line 
Csharp :: ? in c# 
Csharp :: c# initialize array of objects 
Csharp :: wcf service dependency injection 
Csharp :: percentage random c# 
Csharp :: c# dubble comment 
Csharp :: Nested objects with linq expression 
Csharp :: Reading a date from xlsx using open xml sdk 
Csharp :: dotnet.com 
Csharp :: unity transform.translate 
Csharp :: how to round in c# 
Csharp :: unity c# rate game 
Csharp :: euler angles to quaternion unity 
Csharp :: how to convert c# string to pdf 
Csharp :: how to add colider in obj in unity 2020 
Csharp :: make winform open first 
Csharp :: c# pass mouse events to parent 
Html :: font-awesome envelope 
Html :: leading spaces html 
Html :: html input box no border 
Html :: Uncaught ReferenceError: jQuery is not defined 
Html :: regex remove html comment 
Html :: angular click stop propagation 
Html :: facebook share link html 
ADD CONTENT
Topic
Content
Source link
Name
8+3 =