-
July 17th, 2006, 01:49 PM
#1
Accessing Forms controls from a timer callback
I need to update Forms controls based on processing done in a timer delegate.
This is what I get:
A first chance exception of type 'System.InvalidOperationException' occurred in System.Windows.Forms.dll
Additional information: Cross-thread operation not valid: Control 'label4' accessed from a thread other than the thread it was created on.
Is there a workaround?
-
July 18th, 2006, 03:39 AM
#2
Re: Accessing Forms controls from a timer callback
Can you post the code you are using?
-
July 19th, 2006, 09:27 AM
#3
Re: Accessing Forms controls from a timer callback
Cilu:
Thanks for your input, but it seems I found the solution. There is lots of code, so posting it would be problematic, but the problem was that I tried to access, say, "Label->Text=..." from a System::Timers::Timer->Elapsed callback which always runs on a separate thread.
The solution is to use the controls' Invoke method to launch a delegate that would access the control from the UI thread.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|