Solved

Visual Basic Dot Net program - strange crashing problem - main form disappears

Posted on 2004-08-26
26
206 Views
Last Modified: 2010-04-23
I have a VB.NET program that occassionally (and I havent been able to find out exactly what is different on the times that it crashes and does not crash) will crash.  

The strange thing about it is that (1) the main form that the code is running from disappears, but the code for objects that it has called keeps running until it has completed, and also a a Model that launches the Main Form continues to run until it also has run all lines of code (2) I do not get any specific error message, and even though I have error trapping with Try-Catch loops all over the place, I cant seem to find what is failing.

The help I'm looking for is some good diagnostic advice on how to narrow down this problem.  For instance, the fact an object that my main form has called keeps running after the main form crashes, what does this indicate?  

Here is a rough (simplified) sketch of the program:

Main Module
   Form1
       Object1
       Object2
       Object3

The Main module creates form1 as a showdialog (form1.showdialog)
Form1 creates some objects.  Those objects run some code as part of certain property calls
Form1 disappears during a call to a property of an object possibly?  (Form1 is no longer visible in the task bar)
objects continue running code,
main module runs ending code...
program exits

Thank you for the help.
0
Comment
Question by:krose777
  • 10
  • 9
  • 5
  • +2
26 Comments
 
LVL 96

Expert Comment

by:Bob Learned
Comment Utility
Are there any timers?  What are you doing on the form?  Is this on a production machine or can it be duplicated on a development machine?

Bob
0
 
LVL 7

Expert Comment

by:Joe_Griffith
Comment Utility
I don't think this is the recommended way to start a program.  Try looking here:
ms-help://MS.VSCC.2003/MS.MSDNQTR.2004JUL.1033/cpref/html/frlrfSystemWindowsFormsApplicationClassRunTopic.htm

Instead of using Form1.ShowDialog try Application.Run(Form1)
0
 
LVL 18

Expert Comment

by:DotNetLover_Baan
Comment Utility
I don't think ShowDialog() is a problem... I do it all the time and never had any problem. May be the reason is something else... Some code will help us figure it out...
0
 
LVL 2

Author Comment

by:krose777
Comment Utility
There are timers but none are activated during the crash.  It happens on on development and client machine.  I have some decent sized objects that are created, both to store data and run some code.  I believe it is crashing while accessing properties of an object that runs code.  

What I dont understand is why I am running the code from visual studio and it doesnt throw any kind of exception - the form just disappears.  Are there certain type of coding bugs that would cause this?  Problem with an object?  Object modifying something on the calling form?  
0
 
LVL 96

Expert Comment

by:Bob Learned
Comment Utility
What version are you using 2002 or 2003?  Yes, there are a few bugs with Windows Forms, especially in 2002.  We are going to need some more information to give better advice.  Otherwise, it is like searching for a needle in a haystack, but one in which you are blind folded first, so you have to poke around until you get stuck by the needle.  Not a very good approach.

Bob
0
 
LVL 8

Expert Comment

by:wguerram
Comment Utility
Try running the form with no objects.

Then add the objects one bye one.

Add one object, run the form to see what happen, then add another object.

Once you have all the objects, call the  methods you call one by one, do so with event handlers too.

Until you find what object is making the app crash.
0
 
LVL 8

Expert Comment

by:wguerram
Comment Utility
Probably Joe_Griffith is right about running the form Dialog.

Check this:
http://www.experts-exchange.om/Programming/Programming_Languages/Dot_Net/VB_DOT_NET/Q_21100331.html

The form is shown dialog, as a result the SaveDialog is return wrong values.
0
 
LVL 2

Author Comment

by:krose777
Comment Utility
Microsoft Development Environment 2003 when I click on Help/About.
Microsoft Visual Basic .NET   69462-005-0566792-18005
I'm in XP Pro, SP1

One area I keep focusing on is a "progress bar" on my main form.  I allow the object that my main form calls to modify this progress bar by passing the location of the progress bar to the object when I create the object.

ie:

dim myobject as new myobjecttype(progressbar, othervariables)

then during the execution of some code in  myobject, the progressbar's value property will be changed directly from myobject.

Is this something I'm not supposed to do?  Also, if there was a bad value posted to the progressbar.value property from my object, what sort of error would this generate (if any?)

0
 
LVL 8

Accepted Solution

by:
wguerram earned 350 total points
Comment Utility
I made a class that has receives a reference to the form progressbar.

This class has a timer that increments the progressbar.

I placed this code but the error is not beeing trapped.

       Try            
            f.ShowDialog()
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try

In the tick event of the timer that is in the class i placed this code and the error is beeing trapped

       Try
            _p.Value += 1
        Catch ex As Exception
            t.Enabled = False
            MsgBox(ex.Message)
        End Try

What i think is that you are not handling some error in a class or procedure.

That's why i suggested you to try the code one at a time.

0
 
LVL 2

Author Comment

by:krose777
Comment Utility
wguerram,
If you do not trap the error in the class, does it crash the main form with no exception thrown?
0
 
LVL 96

Assisted Solution

by:Bob Learned
Bob Learned earned 150 total points
Comment Utility
Not normally.  You would normally get an Unhandled exception error.  This is sounding like a bug.

Bob
0
 
LVL 8

Expert Comment

by:wguerram
Comment Utility
How TheLearnOne mentioned i get an Unhandled exception error which obviously is not trapped by the Try/catch by the form.
0
 
LVL 2

Author Comment

by:krose777
Comment Utility
Im going to continue to go through the code line by line - doesnt seem like there is an obvious answer, only that I need to find the specific bug in the program.  I'm guessing its something in my object, either a null reference or bad value to the progress bar or something of that nature, that when referenced on the main form causes it to crash, and since there are try-catch loops both in the main form and in the object, VB cant decide how to handle it.  

Thank you both for help, I'll split points...
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 96

Expert Comment

by:Bob Learned
Comment Utility
Does it happen in the IDE?

Bob
0
 
LVL 2

Author Comment

by:krose777
Comment Utility
It happens in the IDE and when running on client machine.
0
 
LVL 2

Author Comment

by:krose777
Comment Utility
When it happens in the IDE, it appears as if the application exited normally, and the same when run on client computer.  Just exits.
0
 
LVL 96

Expert Comment

by:Bob Learned
Comment Utility
When it happens in the IDE, can you put in breakpoints and check when it happens?

Bob
0
 
LVL 96

Expert Comment

by:Bob Learned
Comment Utility
Is the Form_Closing event fired then?
0
 
LVL 2

Author Comment

by:krose777
Comment Utility
I can set breakpoints.  Once or twice I got a "There is no code available for this location" when it tried to break into the debugger - I could not step through the code and when I clicked "run" again, it executed code until exiting "normally" again.  
0
 
LVL 8

Expert Comment

by:wguerram
Comment Utility
Are compiling the project before you run it?

So you will have diferent vesrions of the code while running.

The exe itself and the you code.
0
 
LVL 2

Author Comment

by:krose777
Comment Utility
it compiles each time I run it - I click "Start" in "Debug" mode.  It does a fresh compile each time and then runs.
0
 
LVL 96

Expert Comment

by:Bob Learned
Comment Utility
Are you saying that the Active Configuration is Debug mode and not Release mode?

Bob
0
 
LVL 2

Author Comment

by:krose777
Comment Utility
yes it is in debug mode
0
 
LVL 96

Expert Comment

by:Bob Learned
Comment Utility
Are you using any external references--not just the framework?  Any COM references?

The attribute DebuggerStepThroughAttribute for the forms InitializeComponent means the debugger will not stop within the method, but you can put a breakpoint there.  This way you might see if it is happening during the InitializeForm.

Also, to repeat, is the Form_Closing event firing?  You never answered that question.

Bob
0
 
LVL 2

Author Comment

by:krose777
Comment Utility
I'm not sure if the Form_closing even fires - i believe that it is, but I will need to put some code in the form closing event and test it - I will see if i can crash it again and I'll report back.  

In the code that is crashing, there is usage of the microsoft internet controls "shdocvw.internetexplorer" object.  I use that quite a bit in the object that crashes.
0
 
LVL 96

Expert Comment

by:Bob Learned
Comment Utility
I think that there might be a ray of light shining down on this situation.  Interoperability with COM is flaky sometimes.  Do you have some code that can shed more light on the situation?

Are all the operating system configurations the same for all the crashes?

Bob
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now