Updating Windows Form TextBox.Text w/ a Timer (c#)

  • Thread starter Thread starter Guest
  • Start date Start date
System.InvalidOperationException: Cannot call Invoke or InvokeAsync on a
control until the window handle has been created.

So go on and create the handle if they want it. :-)

The control's handle is needed by the 'magic' plumbing that actually
marshals the call to the control's thread. I have to make sure that the
handle is created *before* other threads try to call into the control.
Accessing the Control.Handle property creates the handle if it hasn't been
created already. Or you can call Control.CreateHandle if you have any
constituent controls...

Best regards,

Palo
---
http://dact.lamarvin.com/
AutoComplete component for WinForms applications. Easy to integrate, easier
to use!
http://www.vbinfozine.com/
An ordinary VB developer shares his own successes and failures
 
Case said:
How might one do this?
Update windows form TextBox.Text w/ a timer(c#). There is a threading
issue here.

Use the System.Windows.Form.Timer instead of the System.Timers.Timer. The
Window Form timer has been made to do exactly what you want without any
threading issue as the delegate call is made in your UI thread instead of
being made in a new thread.
 
Hi Case,

I would suggest the same as Elp did. Using System.WindowsForms.Timer control
you won't have threading problems. However, I want to add that if you insist
using System.Timers.Timer class you can still get rid of the threading
problems setting Timer.SyncronizingObject property with reference to your
Form or control. If that property is set the Timer objects will call
Control's BeginInvoke for you and will switch the execution to the UI
thread.


--
B\rgds
Stoitcho Goutsev (100) [C# MVP]
Case said:
How might one do this?
Update windows form TextBox.Text w/ a timer(c#). There is a threading issue here.

I tried:
http://blogs.msdn.com/csharpfaq/archive/2004/03/17/91685.aspx

And got:
System.InvalidOperationException: Cannot call Invoke or InvokeAsync on a
control until the window handle has been created.
 
Your are probably looking at the MSDN System.Windows.Forms.Timer() documentation. They have the timer even
private static void TimerEventProcessor marked as static. Remove the static keyword, access your text property and presto
-:



----- Case wrote: ----

How might one do this
Update windows form TextBox.Text w/ a timer(c#). There is a threading issue here

I tried
http://blogs.msdn.com/csharpfaq/archive/2004/03/17/91685.asp

And got
System.InvalidOperationException: Cannot call Invoke or InvokeAsync on a control until the window handle has been created

Thanks!
 
Back
Top