Re: Threading problem after migration from 2003 to 2005
- From: Brian Gideon <briangideon@xxxxxxxxx>
- Date: 10 May 2007 08:44:20 -0700
On May 10, 8:49 am, Jeroen <mercu...@xxxxxxxxx> wrote:
We converted our decently large (13 projects, compiled about 12 mb)
VStudio 2003/.Net1.1 project to VStudio 2005/.Net2. My two colleagues
have no problem starting the new solution, but I get an exception
thrown at me. I only get the exception if I run in debug mode, in
release mode all works fine. The exception thrown somewhere along
startup sequence is:
[ InvalidOperationException ]
Cross-thread operation not valid: Control '' accessed from a thread other than the thread it was
created on.
The following snippet shows where the exception is thrown:
----------------------------------------------------------------------
public class PleaseWait : System.Windows.Forms.Form
{
private static PleaseWait fWindow = null;
public static void ShowWindow(string message)
{
if(fWindow == null)
{
fWindow = new PleaseWait();
fWindow.Owner = System.Windows.Forms.Form.ActiveForm;
}
// long i = 0;
// while (i++ < 40000000) ;
fWindow.Show();
// ...etcetera
}}
--------------------------------------------------------------------------
The ShowWindow method is called from somewhere else in the application
during startup. If I uncomment the counter and let it wait for a
while, no exception is thrown. No exception is thrown either if I
break the code just before the Show instruction and wait a few secs.
I have found articles on this but the problem is I cannot distill a
resolution for the mystery the above poses to me. Can anyone provide
an explanation of what's happening with the above info?
Like Andy said it was working in 1.1 by accident. VS 2005 adds the
managed debugging assistant (MDA) to detect this common problem in
debug builds. Strategically placed calls to Control.Invoke or
Control.BeginInvoke may fix the problem. It's been my experience that
some threading problems require significant architectural changes to
fix so let's hope that's not the case here since you have a large
application.
.
- Follow-Ups:
- References:
- Threading problem after migration from 2003 to 2005
- From: Jeroen
- Threading problem after migration from 2003 to 2005
- Prev by Date: Q: Child list for field x cannot be created.
- Next by Date: Re: 32 vs 64 bit
- Previous by thread: Re: Threading problem after migration from 2003 to 2005
- Next by thread: Re: Threading problem after migration from 2003 to 2005
- Index(es):
Relevant Pages
|