B
Beemer Biker
Unaccountably, I cannot re-enable a timer from an background thread. The
disable works fine, I just cannot get it to start back up. There is no
method "InvokeRequired" like there is for windows.forms.controls and I get
no error message about cross thread so I am not sure where the problem is.
I have a "SerialPoll_timer" that every second requests status from a device
on an RS232 port. I use this to determine if the device is on line. There
is a mutex "BusyWriting" associated with the serial port handler to allow
this timer task and other threads to all send info out the same serial port.
This all works fine.
Occassionally, I need to send a long series of initialization commands to
the device. These commands are sent from a background worker thread. Since
there is a long list of commands I thought I would have the background work
disable the serial poll timer, send out all the commands, then re-enable the
serial poll timer.
If I click on a button which does the initialization (ie: the bw thread is
not used) the timer thread gets disabled and re-enabled just fine. When I
started using the background worker to send the initialization commands the
timer never starts back up. This is all I do to the timer. I threw in the
"start" but that didnt help. I can even step thru this code in the debugger
and the timer will not start up. I have to quit the program to get it to
work again.
public void RemoteTimerEnable(bool bEnable)
{
SerialPoll_timer.Enabled = bEnable;
if (bEnable) SerialPoll_timer.Start();
}
So, if I call the above routine from a "button" it works but from a
background task things seem to go wrong. Maybe there is some other
problem? If the timer thread is in the mutex BusyWriteing.WaitOne() when
the disable occures, can this be why it cannot be re-enabled?
disable works fine, I just cannot get it to start back up. There is no
method "InvokeRequired" like there is for windows.forms.controls and I get
no error message about cross thread so I am not sure where the problem is.
I have a "SerialPoll_timer" that every second requests status from a device
on an RS232 port. I use this to determine if the device is on line. There
is a mutex "BusyWriting" associated with the serial port handler to allow
this timer task and other threads to all send info out the same serial port.
This all works fine.
Occassionally, I need to send a long series of initialization commands to
the device. These commands are sent from a background worker thread. Since
there is a long list of commands I thought I would have the background work
disable the serial poll timer, send out all the commands, then re-enable the
serial poll timer.
If I click on a button which does the initialization (ie: the bw thread is
not used) the timer thread gets disabled and re-enabled just fine. When I
started using the background worker to send the initialization commands the
timer never starts back up. This is all I do to the timer. I threw in the
"start" but that didnt help. I can even step thru this code in the debugger
and the timer will not start up. I have to quit the program to get it to
work again.
public void RemoteTimerEnable(bool bEnable)
{
SerialPoll_timer.Enabled = bEnable;
if (bEnable) SerialPoll_timer.Start();
}
So, if I call the above routine from a "button" it works but from a
background task things seem to go wrong. Maybe there is some other
problem? If the timer thread is in the mutex BusyWriteing.WaitOne() when
the disable occures, can this be why it cannot be re-enabled?