Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / July 2007

Tip: Looking for answers? Try searching our database.

Exception when closing threaded splash screen using Invoke

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
hileyj - 23 Jul 2007 23:04 GMT
Hi,

I have an application that seems to crash upon startup in isolated
situations (double clicking an associated file).  I looked into it a little
bit and noticed it was getting to the point where it was closing a splash
screen that the problem occurred.
Example:
In the main form -
 // close the splash screen
 SplashForm.CloseForm();
In the splash form -
   in splash constructor:
   closeDelegate = new CloseDelegate(this.Close);
   hideDelegate = new HideDelegate(this.Hide);
    ...
    public static void CloseForm()
    {
      if (splash != null)
      {
        splash.Invoke(splash.closeDelegate, null);
        Application.DoEvents();
        splash = null;
        thread = null;
      }
    }
    public static HideForm()
   {
      splash.Invoke(splash.hideDelegate, null);
      Application.DoEvents();
   }  

When closing the form, the splash.Invoke... line throws a NullReference
exception, but neither closeDelegate nor splash is null, and appear to be
instantiated properly.
I suspect there is some kind of odd timing/threading issue going on since
this only happens on Win2000 machines.  To make things a little weirder, if I
hide the form first by calling this instead:

 // hide the splash screen
 SplashForm.HideForm();
 SplashForm.CloseForm();

The splash form is closed, the program continues on, and there is no
problem. Any ideas on what the possible cause is here, and why it might be
different on Win2k compared to XP?

Jon Hiley
Peter Duniho - 23 Jul 2007 23:48 GMT
> When closing the form, the splash.Invoke... line throws a NullReference
> exception, but neither closeDelegate nor splash is null, and appear to be
> instantiated properly.

Well, _something_ is null.  If not the closeDelegate or splash variable,  
then what?  .NET doesn't throw NullReference exceptions just for the fun  
of it.  :)

One thing I note is that you don't synchronize access to the splash  
variable.  So you could have a race condition where two different threads  
are using it and then setting it to null.  Whichever thread wins the race  
gets to set the variable to null before the other is done with it, which  
would cause a null exception.  Of course, you didn't post nearly enough  
code for anyone to be able to identify something like that, but it's a  
possibility given the little code that you did post.

If you do post more code, don't post all of it.  Just pare down your code  
to the bare minimum required in order to reproduce the problem, while  
still providing a complete program that can be compiled.

> I suspect there is some kind of odd timing/threading issue going on since
> this only happens on Win2000 machines.  To make things a little weirder,  
[quoted text clipped - 7 lines]
> The splash form is closed, the program continues on, and there is no
> problem.

All that shows is suggest that you do in fact have some sort of  
timing-related thread issue.  Basically, if you have a reproducible error  
case, often when you change the exact operations you do, especially if  
doing so affects the timing of the code, the error goes away.  However,  
since many thread-related bugs are timing-related, that's not really  
useful information, and it doesn't mean you've actually fixed the bug.  It  
just means you've made it harder to debug, because the error no longer  
happens.

Pete

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.