I have a thread as below:
private void SendResultOutThreadSub()
{
bool ExitThread = false;
while (!ExitThread)
{
if(AllTheSignalIsOn)
SendTheResultOut();
if (Interlocked.Equals(icKillAllThreads, 1))
{
Console.WriteLine("Sending result out thread existed");
ExitThread = true;
}
}
}
Can you help to improve my thread coding as above shown?
Before this, I will provide more info about my question:
My project is related with image processing. and I used 2 cameras, with 8 images grabbed by each camera. To decrease the whole processing time, I want to process each image once it was grabbed. In other words, I need process 16 images in total.
After processed, I need combine 2 cameras result (2 outputs, pass or fail) together, as "11", or "10", "00", "01" to other IO device.
In simple:
Camera1 grab 8 sequence images --> Process each images one by one --> If failed 3 times, then camera1 failed;<br />
Camera2 grab 8 sequence images --> Process each images one by one --> If failed 3 times, then camera2 failed;<br />
Send result output: Camera1 result+Camera2 result together;
Above code is for send result out.
1)I am not sure how to improve my send result out thread, as it need wait all the signals?
2)Previously I want to use
WaitHandle.WaitAll(signalArray,100,false)
, but the compiler shows error, as WaitAll only used in MTAThread. So I changed the Main() attribute from
[STAThread]
to
[MTAThread]
(my coding environment is VS C# 2005). But as I have used some 3rd party ActiveX control, which can't be used under
[MTAThread]
, and I had to give up
WaitHandle.WaitAll();
3)I had some trial with WaitAll in console/WinForm application, it runs smoothly in normal state, but when I want to exit the code, seems it has less response to user input. Now I add an "Exit" button on the form, when it was clicked, it will call:
Interlock.Exchange(icKillAllThreads,1);
so you can see I did a check for icKillAllThreads value in above code.
Seems I know little about the 3rd parameters meaning for
public static bool WaitAll(
WaitHandle[] waitHandles,
int millisecondsTimeout,
bool exitContext
);
, can you show me more about this?
Thank you again.