PC Review


Reply
 
 
Jakub Cermak
Guest
Posts: n/a
 
      19th May 2005
Hi all,
sorry for my beginner question.
How can I change a form property from a thread (I don't think primary
application thread, but the instance of Thread class)? If I do it i get
an exception InvalidOperationException - Cross-thread
operation not valid: Control 'lblStatusGame' accessed from a thread
other than the thread it was created on.
--
Best regards,

Jakub Cermak
ICQ 159971304
http://cermi.wz.cz
 
Reply With Quote
 
 
 
 
Jon Skeet [C# MVP]
Guest
Posts: n/a
 
      20th May 2005
Jakub Cermak <(E-Mail Removed)> wrote:
> sorry for my beginner question.
> How can I change a form property from a thread (I don't think primary
> application thread, but the instance of Thread class)? If I do it i get
> an exception InvalidOperationException - Cross-thread
> operation not valid: Control 'lblStatusGame' accessed from a thread
> other than the thread it was created on.


You can't - you need to use Control.Invoke or Control.BeginInvoke.

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

--
Jon Skeet - <(E-Mail Removed)>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
 
Reply With Quote
 
 
 
 
Dmytro Lapshyn [MVP]
Guest
Posts: n/a
 
      20th May 2005
Hi Jakub,

All operations on forms and controls must be done on the main (UI) thread.
If you need to do them from other threads, use the Control.InvokeRequired
and Control.Invoke (see MSDN docs on these for detailed information).

--
Sincerely,
Dmytro Lapshyn [Visual Developer - Visual C# MVP]


"Jakub Cermak" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi all,
> sorry for my beginner question.
> How can I change a form property from a thread (I don't think primary
> application thread, but the instance of Thread class)? If I do it i get an
> exception InvalidOperationException - Cross-thread
> operation not valid: Control 'lblStatusGame' accessed from a thread
> other than the thread it was created on.
> --
> Best regards,
>
> Jakub Cermak
> ICQ 159971304
> http://cermi.wz.cz


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Thread Local Storage and Managed Threads vs O/S Threads Chris Mullins [MVP] Microsoft Dot NET Framework 5 3rd Mar 2007 10:48 PM
Threads Calling Threads? Microsoft C# .NET 1 11th Dec 2006 09:17 PM
Forcing ThreadPool threads to act like they are not background threads orekin Microsoft C# .NET 13 2nd May 2005 07:15 AM
Discussion threads - sorting of internal discussion threads Bill Onwusah Microsoft Outlook 0 30th Jun 2004 03:47 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:12 PM.