jDave1984
jDave1984

Reputation: 972

Code not executing after Threadpool C#

I am trying to run a threadpool, and want to get the runtime of all threads. Here is my code. Am I missing something?

    static void Main(string[] args)
    {

        Console.Write("Enter fund symbol: ");
        String stockSymbol = Console.ReadLine();
        int numberOfFunds = 1;

        String[] fundArray = new String[numberOfFunds];
        ManualResetEvent[] resetEvents = new ManualResetEvent[numberOfFunds];

        var startTime = DateTime.Now;


        for (int s = 0; s < numberOfFunds; s++)
        {

            fundArray[s] = stockSymbol;
            resetEvents[s] = new ManualResetEvent(false);
            ThreadPool.QueueUserWorkItem(new WaitCallback(getStats), (object)fundArray[s]);

        }//END THREADLOOP

        WaitHandle.WaitAll(resetEvents);

        runTime((object)startTime);

        Console.ReadKey();

    }//END MAIN

Upvotes: 0

Views: 56

Answers (1)

EZI
EZI

Reputation: 15364

Seems like you forgot to set resetEvents...

BTW: I would suggest to continue your multithreaded works with Tasks

Upvotes: 1

Related Questions