473,325 Members | 2,805 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

Cross-thread operation not valid ???

I receive this message:
"System.InvalidOperationException: Cross-thread operation not valid: Control
[your_control_name_here] accessed from a thread other than the thread it was
created on"
....
this is a exception. Can fix it?

Nov 23 '06 #1
3 30525
Le Minh wrote:
I receive this message:
"System.InvalidOperationException: Cross-thread operation not valid:
Control [your_control_name_here] accessed from a thread other than
the thread it was created on"
...
this is a exception. Can fix it?
Yes, you can fix it. The exception means that your program accessed a GUI
element from a thread other than the main thread, and that's a no-no.

Use Control.Invoke (or BeginInvoke) to execute the call in the correct
thread.

-cd
Nov 23 '06 #2

Hi,
In VS 2005 Desinging Microsoft Take care abot the major issue. Thread
Synchnization is also change a lot from the 2003 to the 2005 VS.
Actuall when the programm executed, system assign the one thread for
the entire GUI creation and take the changes on the GUI, that will be
[STA Thread]. That thread has the only permission to take the changes
and control the other GUI elements creataed by the STA thraed. If u
create a another threads with the use of System.Threadding.thread,
these thread are not have a enoff previliges to change the GUI elements
on the forms. So u need to write the delegaes from the main thread and
call the delegate function from u r chaild threads, By using this
method u can solve this problem .

public delegate void AddnewTextDelegate(string str);
public void AddTextToTextBox(string str)
{
if (this.textBox1.InvokeRequired)
{
this.Invoke(new AddnewText(AddTextToTextBox), str);
}
else
{
this.textBox1.Text += str;
}

}

The Above exampele shows the add the test to the TextBox in the form.
In the Thread Function just call the AddTextToTextBox("string")
function.
It First call to the Function, In that it check whether the thread has
the certain previlizes or not, If it has it directly add the text to
the textbox, Other wise it again assing the task to the main thread...

All the Best ...
I hope that .. This is inforamtion is reliable ..

On Nov 23, 8:11 am, "Le Minh" <hanami...@hotmail.comwrote:
I receive this message:
"System.InvalidOperationException: Cross-thread operation not valid: Control
[your_control_name_here] accessed from a thread other than the thread it was
created on"
...
this is a exception. Can fix it?
Nov 23 '06 #3
Kodali Ranganadh wrote:
In VS 2005 Desinging Microsoft Take care abot the major issue. Thread
Synchnization is also change a lot from the 2003 to the 2005 VS.
I don't believe that's true. MS has provided BackgroundWorker to make
things easier, but thread synchronization itself is just as it was
before, as far as I'm aware.
Actuall when the programm executed, system assign the one thread for
the entire GUI creation and take the changes on the GUI, that will be
[STA Thread]. That thread has the only permission to take the changes
and control the other GUI elements creataed by the STA thraed. If u
create a another threads with the use of System.Threadding.thread,
these thread are not have a enoff previliges to change the GUI elements
on the forms.
Well, it's not a case of *permissions* - it's a case of thread safety.
It's unsafe (and always has been under Windows, whether doing .NET or
not) to access a UI element except in a few very well-defined ways from
a thread other than the one running its message pump.

<snip>

Jon

Nov 23 '06 #4

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

Similar topics

0
by: Web Science | last post by:
Site and Features: http://www.eigensearch.com Search engine, eigenMethod, eigenvector, mathematical, manifolds, science, technical, search tools, eigenmath, Jacobian, quantum, mechanics,...
12
by: * ProteanThread * | last post by:
but depends upon the clique: ...
3
by: rollasoc | last post by:
Hi, Doing a bit of system testing on a Windows 98 laptop. (.Net 1.1 app). Did a bit of testing. Loaded a previously saved file. A gray box appeared with the text and buttons all white...
0
by: Web Science | last post by:
Site and Features: http://www.eigensearch.com Search engine, eigenMethod, eigenvector, mathematical, manifolds, science, technical, search tools, eigenmath, Jacobian, quantum, mechanics,...
4
by: David Peach | last post by:
Hello, hope somebody here can help me... I have a query that lists defects recorded in a user defined date range. That query is then used as the source for a Cross Tab query that cross-tabs count...
0
by: Web Science | last post by:
Site and Features: http://www.eigensearch.com Search engine, eigenMethod, eigenvector, mathematical, manifolds, science, technical, search tools, eigenmath, Jacobian, quantum, mechanics,...
1
by: Rob Woodworth | last post by:
Hi, I'm having serious problems getting my report to work. I need to generate a timesheet report which will contain info for one employee between certain dates (one week's worth of dates). I...
6
by: Simon | last post by:
Hi All, An experiment i'm doing requires requires a synchronous cross-domain request, without using a proxy. I wondered if anyone had any ideas to help me achieve this. Below is what I have...
6
by: Bart Van der Donck | last post by:
Hello, I'm presenting my new library 'AJAX Cross Domain' - a javascript extension that allows to perform cross-domain AJAX requests. http://www.ajax-cross-domain.com/ Any comments or...
6
by: ampo | last post by:
Hello. Can anyone help with cross-domain problem? I have HTML page from server1 that send xmlHTTPRequest to server2. How can I do it? Thanks.
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.