Cross-thread operation not valid

GrexD

Well-known member
Joined
Mar 5, 2008
Messages
95
Programming Experience
Beginner
Cross-thread operation not valid: Control '' accessed from a thread other than the thread it was created on.

I get this error above at random times when developing in the IDE. This is a new project that I've been working on for about 2 months now and have not distributed it, so I can't say if it will happen once it has been compiled and distributed.

There doesn't seem to be any rhyme or reason to it. It seems to happen either just before or just after anyone of 3 or 4 dialogs that I've designed are opened or closed. Some of these I show as modal and others I don't. If I try and duplicate the error I can't.

When it happens the program does not break on any code line. The program's UI goes away, the compiler is still running, and the error comes up. If I click on 'Continue' on the error dialog I am not taken back to the program. At that point I must stop the compiler and restart to get back to the program.

You'll notice that no control is listed in the error, so I am completely stumped by this. Has anyone else ever encountered anything like this?

Greg
 
Where are you using multiple threads

I didn't know I was.

and where are you accessing controls from other than the UI thread?

I didn't know I was.



I've written 4 complete applications over the last 18 months in VS 08 & 10. I'm not doing anything that I haven't done before. The only difference is that I am using a new collection of 3rd party controls developed by DevComponents. If the error told me which control was causing the problem I could narrow this down.
 
Have you tried putting break points into your code yet? I know it's potentially hard with multiple threads and erratic errors, but it might show you where your error lies in the absence of a useful error message.
Start with one per function and subroutine, and then put one per line on the routine that makes it crash and run it again.
 
This happens once a week at most and I can spend as much as 30 hours a week working on this program. If I started putting break points in the code to that extent I would never get any work done. I have Try...Catch blocks in almost every procedure, but they don't catch it.
 
No I haven't. When the error happens I get a mostly white page added to the IDE with something about no stack trace available...or maybe it is telling me it is available. To be honest, I get lost when looking at it. I'll see what I can see next time, though.
 
Back
Top