Click to See Complete Forum and Search --> : C# need help urgent


Mirtunjay
March 17th, 2008, 03:03 AM
Hi
An unhandled exception of type 'System.InvalidOperationException' occurred in System.Windows.Forms.dll

Additional information: Cross-thread operation not valid: Control 'ctrlForm' accessed from a thread other than the thread it was created on.

How to solve it.

HanneSThEGreaT
March 17th, 2008, 04:24 AM
[ Moved ]

JonnyPoet
March 17th, 2008, 06:44 PM
It seems you are working with different threads. But the information yo give us is like: I cannot drive my car. whats wrong with it.:lol:
If you want help we need eplicit information what you are doing, or if its a very small project zip it and show it here. (delete all binaries, only .cs, project and resource files needed. )

Give specific information: Do you intentionally use different threads ? What do you want to get by doing this... In which line of your code does the error occcur and show that part of code which is relevant for it.
For showing code USE CODE TAGS

Mirtunjay
March 18th, 2008, 12:08 AM
ok i am send link of codeproject.It's a codeproject Example.And i am learnign from it.Here is link:------------

http://www.codeproject.com/KB/IP/NDISmonitor.aspx

JonnyPoet
March 18th, 2008, 07:54 AM
ok i am send link of codeproject.It's a codeproject Example.And i am learnign from it.Here is link:------------

http://www.codeproject.com/KB/IP/NDISmonitor.aspx

So you want us to debug a solution which is done from an author in Codeproject ? Or have youchanged something in the code and now looking for the error, as yu said, you are learnning ?

BTW how much experience do you have in the field of multithreaded applications ?

k_nemelka
March 18th, 2008, 04:20 PM
If you are sure that your application is thread safe then look at CheckForIllegalCrossThreadCalls. Setting this to "false" will resolve your issue.

Mutant_Fruit
March 18th, 2008, 06:19 PM
If you are sure that your application is thread safe then look at CheckForIllegalCrossThreadCalls. Setting this to "false" will resolve your issue.
But if his application *is* threadsafe, this warning will never be fired. If it fires it means there's an issue.

JonnyPoet
March 18th, 2008, 09:32 PM
I have looked into this project and after a correct change from 2003 to 2005 on my machine I couldn't see any problem. It compiles and seems to work fine. Maybe something wrong when updating the code from 2003 to 2005 ?

Mirtunjay
March 19th, 2008, 12:39 AM
How i can change it 2003 to 2005?

JonnyPoet
March 19th, 2008, 09:06 AM
How i can change it 2003 to 2005?Normally if you try to open it in the VS 2005 it asks you to convert it. you simple acknowledge this with Ok.

k_nemelka
March 19th, 2008, 02:57 PM
I have looked into this project and after a correct change from 2003 to 2005 on my machine I couldn't see any problem. It compiles and seems to work fine. Maybe something wrong when updating the code from 2003 to 2005 ?

Search the Microsoft IDE help for "checkforillegalcrossthreadcalls". The very first line says:

"Note: This property is new in the .NET Framework version 2.0"

Thats why you didn't see it in earlier versions of .NET.

I came across this same issue when I migrated an app from 2003 to 2005.

I had a worker thread that was updating a Textbox. Because the worker thread is a different thread than the main thread (the main thread being the one that created the TextBox), I got the "cross threads" error. I set the checkforillegalcrossthreadcalls to false because I *knew* that doing so would always be safe. The application runs 24x7 and I have never had any cross threading issues relating to setting the checkforillegalcrossthreadcalls to false.

So, "mutant_fruit", you are absolutely correct in saying that there is an issue if you get the cross threads error. My point, though, is that the issue may in fact be a non-issue.


kdn

Mutant_Fruit
March 19th, 2008, 05:04 PM
So, "mutant_fruit", you are absolutely correct in saying that there is an issue if you get the cross threads error. My point, though, is that the issue may in fact be a non-issue
If you are in 100% control of all threads that events are being fired from, you can get away with it. Otherwise you can't. That means if you use a library you have not personally written, you can have issues.

The best thing about race conditions is that they can show up once in a blue moon and be very hard to catch and debug. That's why leaving that warning enabled is good and helps remove all possibility of a bug appearing.

JonnyPoet
March 19th, 2008, 07:07 PM
Search the Microsoft IDE help for "checkforillegalcrossthreadcalls". The very first line says:

"Note: This property is new in the .NET Framework version 2.0"

Thats why you didn't see it in earlier versions of .NET.

I came across this same issue when I migrated an app from 2003 to 2005.
Yes I know that. BUT
1) Its not his program
2) He even doesn't know what this message meands so how he can be sure that this is no issue in Framework 2.0
3) I didn't get this message at starting the application and I havn't set the check to off.
Therefore he should exactly tell us where the error occurs and in which condition this happens. Then the design needs to be adapted so the problem is really solved. Normally this shouldn't be very difficult if its a matter with a textbox as in your example.

but giving errormessages without any specific detail of the codepart where it occured cannot be handled here. ;) As thi is too less information