473,660 Members | 2,468 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

(VS 2005 Beta)Illegal cross-thread operation

What I should do to return back the permissin I had in VS2003 , that allowd
me to access public methode of one Class from other Thread.

I have Class A(FORM) which create new thread (new class B), the new class
thread get as parameter reference to his father( CLASS who mad it (classA)),
The new thread need to call methodes from his father like myfathe.methode (),
This worked in VS 2003 but now in VS 2005 Beta throw an exception :

An unhandled exception of type 'System.Invalid OperationExcept ion' occurred
in System.Windows. Forms.dll

Additional information: Illegal cross-thread operation: Control
'Green_pictureB ox1' accessed from a thread other than the thread it was
created on.
Stack trace where the illegal operation occurred was:

at System.Windows. Forms.Control.g et_Handle()
at System.Windows. Forms.Control.S etVisibleCore(B oolean)
at System.Windows. Forms.Control.s et_Visible(Bool ean)
at Mynamespace.Tes t_Board_Main_Fo rm.Green_origin alimageI_Light( Boolean)
at Mynamespace.Exe cuteThread.Firm wareUpdateDll()
Nov 16 '05 #1
12 2369
[Yosi] <Yo**@discussio ns.microsoft.co m> wrote:
What I should do to return back the permissin I had in VS2003 , that allowd
me to access public methode of one Class from other Thread.


It's not that it's a class, it's that it's a UI class. Although
changing properties on UI elements from another thread would
*sometimes* work with .NET 1.1, it was still a *very bad idea*.

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

I'm glad to see it's now being caught early rather than allowing broken
code to work sometimes.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #2
In VS2003 you were doing something Very Bad (tm). You we're updating the UI from the wrong thread which is not supported by the underlying windowing system. VS2005 now catches this to prevent you from shooting yourself in the foot.

Regards

Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk/weblog
http://www.dotnetconsult.co.uk

What I should do to return back the permissin I had in VS2003 , that allowd
me to access public methode of one Class from other Thread.

I have Class A(FORM) which create new thread (new class B), the new class
thread get as parameter reference to his father( CLASS who mad it (classA)),
The new thread need to call methodes from his father like myfathe.methode (),
This worked in VS 2003 but now in VS 2005 Beta throw an exception :

An unhandled exception of type 'System.Invalid OperationExcept ion' occurred
in System.Windows. Forms.dll

Additional information: Illegal cross-thread operation: Control
'Green_pictureB ox1' accessed from a thread other than the thread it was
created on.
Stack trace where the illegal operation occurred was:

at System.Windows. Forms.Control.g et_Handle()
at System.Windows. Forms.Control.S etVisibleCore(B oolean)
at System.Windows. Forms.Control.s et_Visible(Bool ean)
at Mynamespace.Tes t_Board_Main_Fo rm.Green_origin alimageI_Light( Boolean)
at Mynamespace.Exe cuteThread.Firm wareUpdateDll()

Nov 16 '05 #3
Jon,

Note that it's only caught when running in the debugger, nothing has changed
in non debug mode.

Willy.

"Jon Skeet [C# MVP]" <sk***@pobox.co m> wrote in message
news:MP******** *************** *@msnews.micros oft.com...
[Yosi] <Yo**@discussio ns.microsoft.co m> wrote:
What I should do to return back the permissin I had in VS2003 , that
allowd
me to access public methode of one Class from other Thread.


It's not that it's a class, it's that it's a UI class. Although
changing properties on UI elements from another thread would
*sometimes* work with .NET 1.1, it was still a *very bad idea*.

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

I'm glad to see it's now being caught early rather than allowing broken
code to work sometimes.

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

Nov 16 '05 #4
Willy Denoyette [MVP] <wi************ *@pandora.be> wrote:
Note that it's only caught when running in the debugger, nothing has changed
in non debug mode.


Interesting. I suppose that's reasonable on performance grounds. Let's
just hope people do actually run things at least once in debug mode :)

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #5
[Yosi] <Yo**@discussio ns.microsoft.co m> wrote:
Since Microsoft Allowd such a bad thing, there are product doing this bad
think , It's is so bad that Microsoft don't alowd this any more , if this
true, Microsoft must inform all those companies about this , so they can
decide if to buy the new VS2005 or not, (if to continue use the bad usage or
to make new release with the fix..)
I think they should add an option to allowd this or not (my in security
option list).


No. It's not something that they've just disallowed - it's *always*
been dangerous, and it's always been talked about all over the place.
It's not like it's not documented. It's just that now in debug mode the
mistakes can be found more clearly.

Your code was broken under VS.NET 2003 - it just wasn't as *obviously*
broken.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #6
Yes, I guess they didn't want to burn some CPU cycles for this in a release
built, the problem is that you shouldn't need to run in the debugger for
this to show up. I'm pretty sure most of us will only unit-test when moving
existing applications to v2.0 and 'problems' like this will simply pass the
test runs.
I just finished a code review for a large number of windows forms
applications, you would be surprised of the number of applications failing
to obey this UI threading rule. The reactions (some) of the (professional)
developers goes like this: "Oh, it's probably the debugger" or "normal, this
thing is still in beta, right" or "MSFT broke my code" or "Never heard about
this and it's not documented" etc.

Willy.
"Jon Skeet [C# MVP]" <sk***@pobox.co m> wrote in message
news:MP******** *************** *@msnews.micros oft.com...
Willy Denoyette [MVP] <wi************ *@pandora.be> wrote:
Note that it's only caught when running in the debugger, nothing has
changed
in non debug mode.


Interesting. I suppose that's reasonable on performance grounds. Let's
just hope people do actually run things at least once in debug mode :)

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

Nov 16 '05 #7
Willy Denoyette [MVP] <wi************ *@pandora.be> wrote:
Yes, I guess they didn't want to burn some CPU cycles for this in a release
built, the problem is that you shouldn't need to run in the debugger for
this to show up.
True.
I'm pretty sure most of us will only unit-test when moving
existing applications to v2.0 and 'problems' like this will simply pass the
test runs.
I guess that's a good reason to run unit tests in the debugger as well
as not. At least once :)
I just finished a code review for a large number of windows forms
applications, you would be surprised of the number of applications failing
to obey this UI threading rule. The reactions (some) of the (professional)
developers goes like this: "Oh, it's probably the debugger" or "normal, this
thing is still in beta, right" or "MSFT broke my code" or "Never heard about
this and it's not documented" etc.


Yes - scary, isn't it?

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #8
OK, I didn't try to run in Release mode, any way I thoght it is the easy way
to do what I had done,
I don't access the UI components directly , I use a public methode , I still
don't think this is a bad think since I mad a public methosd, those public
methodes access the components. Why this is a bad thing.
I have one function read from USB target, as you know if target didn't
transmit the data the host will keep asking for this data, So all I tried to
do is to make this function run in another thread and before start it I start
a timer to kill it when time is out. this function call an out funtion whitch
print out the data recived from USB .
the out is a UI thread which caled from the USB thread,

"Jon Skeet [C# MVP]" wrote:
[Yosi] <Yo**@discussio ns.microsoft.co m> wrote:
Since Microsoft Allowd such a bad thing, there are product doing this bad
think , It's is so bad that Microsoft don't alowd this any more , if this
true, Microsoft must inform all those companies about this , so they can
decide if to buy the new VS2005 or not, (if to continue use the bad usage or
to make new release with the fix..)
I think they should add an option to allowd this or not (my in security
option list).


No. It's not something that they've just disallowed - it's *always*
been dangerous, and it's always been talked about all over the place.
It's not like it's not documented. It's just that now in debug mode the
mistakes can be found more clearly.

Your code was broken under VS.NET 2003 - it just wasn't as *obviously*
broken.

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

Nov 16 '05 #9
[Yosi] <Yo**@discussio ns.microsoft.co m> wrote:
OK, I didn't try to run in Release mode, any way I thoght it is the easy way
to do what I had done,
I don't access the UI components directly , I use a public methode , I still
don't think this is a bad think since I mad a public methosd, those public
methodes access the components. Why this is a bad thing.
But calling methods which access the components still means you end up
accessing the components from the wrong thread, doesn't it? That
violates the rules specified in the Control documentation.
I have one function read from USB target, as you know if target didn't
transmit the data the host will keep asking for this data, So all I tried to
do is to make this function run in another thread and before start it I start
a timer to kill it when time is out. this function call an out funtion whitch
print out the data recived from USB .
the out is a UI thread which caled from the USB thread,


Not sure what you mean by "the out". See
http://www.pobox.com/~skeet/csharp/t...winforms.shtml for how to
invoke a delegate on the UI thread from a different thread.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #10

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

Similar topics

3
5891
by: Marcus | last post by:
Hi I have a very complex sql query and a explain plan. I found there is a full table scan in ID=9 9 8 TABLE ACCESS (FULL) OF 'F_LOTTXNHIST' (Cost=84573 Card=185892 Bytes=7063896) How can I correlate which part of the SQL statement is running on full table scan. Please see below for the code and explain plan SQL Code
6
2132
by: sathyashrayan | last post by:
Following are the selected thread from the date:30-jan-2005 to 31-jan-2005. I did not use any name because of the subject is important. You can get the original thread by typing the subject "string" in google comp.lang.c archives.Hope this helps.Hope I am not bothering any one. am I? =================================Start=========================== subject: Return to Start of Line? Question: I'd like printf, the next printf, to return...
2
7417
by: Benny | last post by:
I have a richtextbox that acts like a console with information on the status of the server I am creating. I spawn new threads for each connection that is created and would like to write the status to the console. When I try to do that right now it gives me the error "Cross-thread operation not valid: Control 'rtbConsole' accessed from a thread other than the thread it was created on." Thanks in advance!s
4
2928
by: Joe | last post by:
I'm hosting my web service on a Windows 2003 box which is remotely located. When trying to add a web reference to a C# project I get an error message 'There was an error downloading 'http://mydomain.com:port/webservice.asmx' The operation has timed-out (I've tried with and without using a separate port for the service) The weird thing is the page does show up on the left side of the screen listing the available methods but the Add...
0
3581
by: Mart | last post by:
Hi, I have just written (my first) VB.net app using MS Visual Basic 2005 Express Edition Beta. It is fairly simple, it reads some configuration data from an XML file then opens a new window containing a WebBrowser object. This all works fine and I'm happy with my app so I want to 'publish' to a setup file so that others can install it, but when I publish it a get the following errors:
0
1778
by: pumaken68 | last post by:
Does anyone has experience with calling web service from pocket pc 2003 project in VS 2005 environment? I just migrated a smart device(pocket pc 2003) solution from VS 2003 to VS 2005. There are 3 projects inside solution: 1. pocket PC 2003 windows form project; 2. Business rules 3. a web service which will be used to download and upload data via wireless from/to backend database. After converted and built successfully, the web service...
1
6548
by: Stout | last post by:
Is it possible to create a trigger in one database, that after an insert, will update a database on a different server? If so, how would I do this? Thanks. Bill
0
3530
by: fischermx | last post by:
Environment: Microsoft Visual Studio 2005 Version 8.0.50727.762 (SP.050727-7600) Microsoft .NET Framework Version 2.0.50727 Microsoft Visual Studio 2005 Professional Edition - ENU Service Pack 1 (KB926601) Hotfix for Microsoft Visual Studio 2005 Professional Edition - ENU (KB933608) Windows XP, SP2.
0
3130
by: Default User | last post by:
I work on creating test cases for a SOAP-based set of servers, using soapUI. I received and updated set of WSDL and schema files, and when I made new tests and mock server operations, all of the ones that had been working now returned a SOAP fault. The faults look something like: <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope"> <soap:Body> <soap:Fault> <soap:Code>
0
8428
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8341
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8630
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7360
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6181
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5650
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4176
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
1982
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1739
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.