How to know when ThreadPoll is finish?
-
Hey! I am using the following code in a event(SerialPort.RecivedData event) that fires whenever data is written to a stream(serialPort)
if (RUNNING) { ThreadPool.QueueUserWorkItem(new WaitCallback(onDataReceived)); currentRunningThreads++; }
in OnDatareceived the serialPort is used to read the existing data. Now i need to close this serialPort, but i get errors without any source to show? I am setting Running to false, but that is not solving it? How can a see when the ThreadPools threads realy is finish with theres jobb? Best Regards Snowjim -
Hey! I am using the following code in a event(SerialPort.RecivedData event) that fires whenever data is written to a stream(serialPort)
if (RUNNING) { ThreadPool.QueueUserWorkItem(new WaitCallback(onDataReceived)); currentRunningThreads++; }
in OnDatareceived the serialPort is used to read the existing data. Now i need to close this serialPort, but i get errors without any source to show? I am setting Running to false, but that is not solving it? How can a see when the ThreadPools threads realy is finish with theres jobb? Best Regards SnowjimA more Specified error message: First a MessageBox that says that there is no source code to be displayed. Then a smaller box appers Title: ObjectDisposedException was unhandled safe handler has been closed I do have try and catch on every method i have but this exception is never runned(if it would i could see where the error is appering in my code)
-
Hey! I am using the following code in a event(SerialPort.RecivedData event) that fires whenever data is written to a stream(serialPort)
if (RUNNING) { ThreadPool.QueueUserWorkItem(new WaitCallback(onDataReceived)); currentRunningThreads++; }
in OnDatareceived the serialPort is used to read the existing data. Now i need to close this serialPort, but i get errors without any source to show? I am setting Running to false, but that is not solving it? How can a see when the ThreadPools threads realy is finish with theres jobb? Best Regards SnowjimOne solution would be to create an event CloseSerialPort and call it from the onDataReceived method when it has finished it's job. Then you could put all the code needed to close your serial port in the event handler. I reject your reality and substitute my own! - Adam Savage, Mythbuster -George W Bush life is like a roll of toilet paper. The closer it gets to the end, the faster it goes.
-
Hey! I am using the following code in a event(SerialPort.RecivedData event) that fires whenever data is written to a stream(serialPort)
if (RUNNING) { ThreadPool.QueueUserWorkItem(new WaitCallback(onDataReceived)); currentRunningThreads++; }
in OnDatareceived the serialPort is used to read the existing data. Now i need to close this serialPort, but i get errors without any source to show? I am setting Running to false, but that is not solving it? How can a see when the ThreadPools threads realy is finish with theres jobb? Best Regards SnowjimInstead of directly using ThreadPool, you can try wrapping
OnDataReceived
in a delegate and callingBeginInvoke
on the delegate. That'll allow you to pass a callback that'll get called onceOnDataReceived
completes. Even otherwise,BeginInvoke
returns anIAsyncResult
that has a bool propertyIsCompleted
that you can query to find out if the method has completed. Regards Senthil _____________________________ My Blog | My Articles | WinMacro -
One solution would be to create an event CloseSerialPort and call it from the onDataReceived method when it has finished it's job. Then you could put all the code needed to close your serial port in the event handler. I reject your reality and substitute my own! - Adam Savage, Mythbuster -George W Bush life is like a roll of toilet paper. The closer it gets to the end, the faster it goes.
How do i know when to call this CloseSerialPort in onDataReceived method? consider this: SerialPort.RecievedData event is triggerd Job is added to the threadpool that points to the onDataReveived method SerialPort.RecievedData event is triggerds 5 times and diffrent threads are working there way thow onDataReceived that contains a look part. By this i will not know what thread that is the last one. I need to close this threads before i can call serialport.close();