Re: Threading problem after migration from 2003 to 2005

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



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.

.



Relevant Pages

  • Threading problem after migration from 2003 to 2005
    ... VStudio 2003/.Net1.1 project to VStudio 2005/.Net2. ... have no problem starting the new solution, but I get an exception ... The exception thrown somewhere along ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Validating file names
    ... running Novel, from your G: running Linux file system, from your H: running ... I am not saying one does not exist! ... file file and handle any exceptions that were thrown. ... If an exception is thrown then the specified ...
    (microsoft.public.dotnet.languages.vb)
  • Re: isColor()?
    ... I misunderstood your comment to be related to the intended behavior ... actually does in the browsers it's tested in. ... Doing that would hide any exception and, ... an exception required to be thrown. ...
    (comp.lang.javascript)
  • Re: Using an ActiveX ocx control on a Webform
    ... > download the ActiveX I can Automate the ActiveX object through the ... > Exception of type InvalidActiveXStateException was thrown. ... > tried using the item in the design mode of a regular .NET Windows ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Exception-Objekt freigeben
    ... When an exception is thrown, the exception object that is thrown is destroyed ... we have added the AcquireExceptionObject and ReleaseExceptionObject functions. ... then the thrown object is not destroyed by the RTL, but assumed to be in control ...
    (de.comp.lang.delphi.misc)