473,480 Members | 1,940 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Threads

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
Nov 17 '05 #1
4 3339
Jakub Cermak <ja******@centrum.cz> 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 - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 17 '05 #2
Jakub Cermak <ja******@centrum.cz> 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 - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 17 '05 #3
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" <ja******@centrum.cz> wrote in message
news:u3**************@TK2MSFTNGP09.phx.gbl...
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


Nov 17 '05 #4
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" <ja******@centrum.cz> wrote in message
news:u3**************@TK2MSFTNGP09.phx.gbl...
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


Nov 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
5374
by: Ronan Viernes | last post by:
Hi, I have created a python script (see below) to count the maximum number of threads per process (by starting new threads continuously until it breaks). ###### #testThread.py import...
0
1995
by: Al Tobey | last post by:
I was building perl 5.8.2 on RedHat Enterprise Linux 3.0 (AS) today and noticed that it included in it's ccflags "-DTHREADS_HAVE_PIDS." I am building with -Dusethreads. With newer Linux...
6
3169
by: m | last post by:
Hello, I have an application that processes thousands of files each day. The filenames and various related file information is retrieved, related filenames are associate and placed in a linked...
34
10729
by: Kovan Akrei | last post by:
Hi, I would like to know how to reuse an object of a thread (if it is possible) in Csharp? I have the following program: using System; using System.Threading; using System.Collections; ...
3
22148
by: bygandhi | last post by:
Hi - I am writing a service which will check a process and its threads for their state ( alive or dead ). The process has 5 .net managed threads created using thread.start and each have been...
10
1656
by: [Yosi] | last post by:
I would like to know how threads behavior in .NET . When an application create 4 threads for example start all of them, the OS task manager will execute all 4 thread in deterministic order manes,...
6
2501
by: RahimAsif | last post by:
Hi guys, I would like some advice on thread programming using C#. I am writing an application that communicates with a panel over ethernet, collects data and writes it to a file. The way the...
3
5953
by: mjheitland | last post by:
Hi, I like to know how many threads are used by a Threading.Timer object. When I create a Threading.Timer object calling a short running method every 5 seconds I expected to have one additional...
10
1733
by: Darian | last post by:
Is there a way to find all the thread names that are running in a project? For example, if I have 5 threads T1, T2, T3, T4, T5...and T2, T4, and T5 are running...I want to be able to know that...
4
2244
by: tdahsu | last post by:
All, I'd appreciate any help. I've got a list of files in a directory, and I'd like to iterate through that list and process each one. Rather than do that serially, I was thinking I should...
0
6908
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7044
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7084
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6739
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5337
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4779
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4481
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
2995
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1300
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.