K
Kerem Gümrükcü
Hi,
i have a main thread an another worker thread.
The main Thread creates another thread and waits
for the threads signal to continue the main thread.
Everything works inside a ModalDialog and everyting
is secured by Invoke/BeginInvoke, and synchronisation
primitves like WaitHandles, Evetns, Semaphores, etc...
All works good and with no race conditions or locks.
I have a System.Windows.Forms.Timer in the main
Thread that must stopped from the second thread.
Using a code like does not stop the Timer and the
Message is obviousy clear to me, but how can i
stop the Timer on the Form from another Thread
that still s running? Thats what i get with that code:
private delegate void DisableTimerDelegate();
private void DisableTimer()
{
this.timerServiceTimeoutTimer.Enabled = false;
}
this.Invoke(new DisableTimerDelegate(this.DisableTimer));
Leads to this Exception:
System.InvalidOperationException: Invoke oder BeginInvoke kann für ein
Steuerelement erst aufgerufen werden, wenn das Fensterhandle erstellt wurde.
bei System.Windows.Forms.Control.MarshaledInvoke(Control caller, Delegate
method, Object[] args, Boolean synchronous)
bei System.Windows.Forms.Control.Invoke(Delegate method, Object[] args)
bei System.Windows.Forms.Control.Invoke(Delegate method)
bei
DeviceRemover.Forms.DRKernelCommandProgressClass.ServiceCommandThread(Object
parameter) in
C:\projects\DeviceRemover\Forms\DRKernelCommandProgressClass.cs:Zeile 986.
bei System.Threading.ThreadHelper.ThreadStart_Context(Object state)
bei System.Threading.ExecutionContext.Run(ExecutionContext
executionContext, ContextCallback callback, Object state)
bei System.Threading.ThreadHelper.ThreadStart(Object obj)
Translated says something like ""Invoke or BeginInvoke can only be called
for a Control if the WindowHandle has been created for it"
How can i "safely" stop that Timer from my second thread
in the main thread?
Thanks in advance,...
Regards
Kerem
--
i have a main thread an another worker thread.
The main Thread creates another thread and waits
for the threads signal to continue the main thread.
Everything works inside a ModalDialog and everyting
is secured by Invoke/BeginInvoke, and synchronisation
primitves like WaitHandles, Evetns, Semaphores, etc...
All works good and with no race conditions or locks.
I have a System.Windows.Forms.Timer in the main
Thread that must stopped from the second thread.
Using a code like does not stop the Timer and the
Message is obviousy clear to me, but how can i
stop the Timer on the Form from another Thread
that still s running? Thats what i get with that code:
private delegate void DisableTimerDelegate();
private void DisableTimer()
{
this.timerServiceTimeoutTimer.Enabled = false;
}
this.Invoke(new DisableTimerDelegate(this.DisableTimer));
Leads to this Exception:
System.InvalidOperationException: Invoke oder BeginInvoke kann für ein
Steuerelement erst aufgerufen werden, wenn das Fensterhandle erstellt wurde.
bei System.Windows.Forms.Control.MarshaledInvoke(Control caller, Delegate
method, Object[] args, Boolean synchronous)
bei System.Windows.Forms.Control.Invoke(Delegate method, Object[] args)
bei System.Windows.Forms.Control.Invoke(Delegate method)
bei
DeviceRemover.Forms.DRKernelCommandProgressClass.ServiceCommandThread(Object
parameter) in
C:\projects\DeviceRemover\Forms\DRKernelCommandProgressClass.cs:Zeile 986.
bei System.Threading.ThreadHelper.ThreadStart_Context(Object state)
bei System.Threading.ExecutionContext.Run(ExecutionContext
executionContext, ContextCallback callback, Object state)
bei System.Threading.ThreadHelper.ThreadStart(Object obj)
Translated says something like ""Invoke or BeginInvoke can only be called
for a Control if the WindowHandle has been created for it"
How can i "safely" stop that Timer from my second thread
in the main thread?
Thanks in advance,...
Regards
Kerem
--