J
jodleren
Hi
I have some components, which have a calculate thread (each). The
thread is started when needed, then I use monitor.pulse to make it go
again... it works, but when I need to shut it down (setting a
"terminate" varible for that), and call
Monitor.Enter(CalcThread.trigger);
Monitor.Pulse(CalcThread.trigger);
Monitor.Exit(CalcThread.trigger);
Then it does not trig anything..... how come?
The thread is:
public void Execute()
{
Monitor.Enter(trigger);
for (; !terminated; )
{
try
{
OpenConnection();
.... database stuff....
}
catch (Exception e)
{
object[] myArray = new object[2];
myArray[0] = this;
myArray[1] = "Thread error: " + e.Message;
host.BeginInvoke(host.passerroron, myArray);
}
finally
{
CloseConnection();
}
Monitor.Wait(trigger);
}
Monitor.Exit(trigger); // *** waits forever here....
host.BeginInvoke(host.statTerminated);
}
}
I have some components, which have a calculate thread (each). The
thread is started when needed, then I use monitor.pulse to make it go
again... it works, but when I need to shut it down (setting a
"terminate" varible for that), and call
Monitor.Enter(CalcThread.trigger);
Monitor.Pulse(CalcThread.trigger);
Monitor.Exit(CalcThread.trigger);
Then it does not trig anything..... how come?
The thread is:
public void Execute()
{
Monitor.Enter(trigger);
for (; !terminated; )
{
try
{
OpenConnection();
.... database stuff....
}
catch (Exception e)
{
object[] myArray = new object[2];
myArray[0] = this;
myArray[1] = "Thread error: " + e.Message;
host.BeginInvoke(host.passerroron, myArray);
}
finally
{
CloseConnection();
}
Monitor.Wait(trigger);
}
Monitor.Exit(trigger); // *** waits forever here....
host.BeginInvoke(host.statTerminated);
}
}