Threading Exception!!!!

V

Vai2000

Hi All, I am running into an exception with my Multithreaded App. (This app
is derived from IServicedComponent). I am calling a method with ThreadPool
ThreadPool.QueueUserWorkItem(new WaitCallback(Foo), stateInfo);

void DoSomething()
{

ManualResetEvent[] manualEvents = new ManualResetEvent[5];
manualEvents = new ManualResetEvent(false);

ThreadPool.QueueUserWorkItem(new WaitCallback(Foo), stateInfo);

if(WaitHandle.WaitAll(manualEvents)) // THROWING EXCEPTION SAYING OBJECT
REF....SEE BELOW
Console.Write("Done");

}

void Foo(object key)
{
// set the event
}


Failed in Processing: Stack Trace- at
System.Threading.WaitHandle.WaitMultiple(WaitHandle[] waitHandles, Int32
millisecondsTimeout, Boolean exitContext, Boolean WaitAll)
at System.Threading.WaitHandle.WaitAll(WaitHandle[] waitHandles, Int32
millisecondsTimeout, Boolean exitContext)
at System.Threading.WaitHandle.WaitAll(WaitHandle[] waitHandles, TimeSpan
timeout, Boolean exitContext)
Message-Object reference not set to an instance of an object.
Inner Exception-
Source-mscorlib
Base Exception Message-Object reference not set to an instance of an object.
Base Stack Trace- at System.Threading.WaitHandle.WaitMultiple(WaitHandle[]
waitHandles, Int32 millisecondsTimeout, Boolean exitContext, Boolean
WaitAll)
at System.Threading.WaitHandle.WaitAll(WaitHandle[] waitHandles, Int32
millisecondsTimeout, Boolean exitContext)
at System.Threading.WaitHandle.WaitAll(WaitHandle[] waitHandles, TimeSpan
timeout, Boolean exitContext)
Base Source-mscorlib
 
R

Richard A. Lowe

Are you sure you set ever element of the manualEvents array to an instance
of a ManualResetEvent? Your code below doesn't make it look like you do...
(it looks like you only set the i-th element, whatever the value of i is)

Richard
 
V

Vai2000

Yes I do set the all elements of ManualResetEvents array correctly
sorry for posting incomplete code
for(int idx=0;idx<5;idx++)
{
manualEvents = new ManualResetEvent(false);
ThreadPool.QueueUserWorkItem(new WaitCallback(Foo), stateInfo);
}


TIA

Richard A. Lowe said:
Are you sure you set ever element of the manualEvents array to an instance
of a ManualResetEvent? Your code below doesn't make it look like you do...
(it looks like you only set the i-th element, whatever the value of i is)

Richard

--
C#, .NET and Complex Adaptive Systems:
http://blogs.geekdojo.net/Richard
Vai2000 said:
Hi All, I am running into an exception with my Multithreaded App. (This app
is derived from IServicedComponent). I am calling a method with ThreadPool
ThreadPool.QueueUserWorkItem(new WaitCallback(Foo), stateInfo);

void DoSomething()
{

ManualResetEvent[] manualEvents = new ManualResetEvent[5];
manualEvents = new ManualResetEvent(false);

ThreadPool.QueueUserWorkItem(new WaitCallback(Foo), stateInfo);

if(WaitHandle.WaitAll(manualEvents)) // THROWING EXCEPTION SAYING OBJECT
REF....SEE BELOW
Console.Write("Done");

}

void Foo(object key)
{
// set the event
}


Failed in Processing: Stack Trace- at
System.Threading.WaitHandle.WaitMultiple(WaitHandle[] waitHandles, Int32
millisecondsTimeout, Boolean exitContext, Boolean WaitAll)
at System.Threading.WaitHandle.WaitAll(WaitHandle[] waitHandles, Int32
millisecondsTimeout, Boolean exitContext)
at System.Threading.WaitHandle.WaitAll(WaitHandle[] waitHandles, TimeSpan
timeout, Boolean exitContext)
Message-Object reference not set to an instance of an object.
Inner Exception-
Source-mscorlib
Base Exception Message-Object reference not set to an instance of an object.
Base Stack Trace- at System.Threading.WaitHandle.WaitMultiple(WaitHandle[]
waitHandles, Int32 millisecondsTimeout, Boolean exitContext, Boolean
WaitAll)
at System.Threading.WaitHandle.WaitAll(WaitHandle[] waitHandles, Int32
millisecondsTimeout, Boolean exitContext)
at System.Threading.WaitHandle.WaitAll(WaitHandle[] waitHandles, TimeSpan
timeout, Boolean exitContext)
Base Source-mscorlib

 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top