Re: Cross-thread operation not valid



Mikael Syska <news04@xxxxxxxx> wrote:
> Cross-thread operation not valid: Control 'ThreadStartedAt' accessed
> from a thread other than the thread it was created on
>
> I get this Exception when I try to update some labels/textbox's from a
> Thread... I have read something about that I can use Delegates/Invoke
> and stuff in that direction, but I'm not that far in my book now that I
> understand how all that works....
>
> Is there any one here that can give a very simple example, I can use in
> my Program to update some controls on my form from a Thread?

You can't, directly. You have to call Control.Invoke/BeginInvoke to do
the actual update on the UI thread.

See http://www.pobox.com/~skeet/csharp/winforms.shtml

--
Jon Skeet - <skeet@xxxxxxxxx>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
.



Relevant Pages

  • Re: Raise event inside a thread
    ... using monitors or a ManualResetEvent. ... Jon Skeet - ... If replying to the group, please do not mail me too ... Prev by Date: ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: get the actual size of a file
    ... saying for certain either way:) ... Jon Skeet - ... If replying to the group, please do not mail me too ... Prev by Date: ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Threading/Locking
    ... Then you stash the data in an ordered list which is then processed by ... Jon Skeet - ... If replying to the group, please do not mail me too ... Prev by Date: ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: How to trigger other thread
    ... updates are "seen" or not. ... Jon Skeet - ... If replying to the group, please do not mail me too ... Prev by Date: ...
    (microsoft.public.dotnet.framework.windowsforms)
  • Re: MemoryStream.Write() Offset cannot be zero
    ... a file - it's just like that, except it all stays in memory. ... Jon Skeet - ... If replying to the group, please do not mail me too ... Prev by Date: ...
    (microsoft.public.dotnet.framework)

Loading