Simon,
| The symptom that users report is that after they have been using the
| application for a while, it will randomly just crash with an
| exception report (I've not got the details of the error, but
| I'm working on that now!).
You may want to include one or more Global Exception handlers in your
program to log any exception reports from "random" crashes.
Depending on the type of application you are creating, .NET has three
different global exception handlers.
For ASP.NET look at:
System.Web.HttpApplication.Error event
Normally placed in your Global.asax file.
For console applications look at:
System.AppDomain.UnhandledException event
Use AddHandler in your Sub Main.
For Windows Forms look at:
System.Windows.Forms.Application.ThreadException event
Use AddHandler in your Sub Main.
It can be beneficial to combine the above global handlers in your app, as
well as wrap your Sub Main in a try catch itself.
There is an article in the June 2004 MSDN Magazine that shows how to
implement the global exception handling in .NET that explains why & when you
use multiple of the above handlers...
http://msdn.microsoft.com/msdnmag/is...T/default.aspx
For example: In my Windows Forms apps I would have a handler attached to the
Application.ThreadException event, plus a Try/Catch in my Main. The
Try/Catch in Main only catches exceptions if the constructor of the MainForm
raises an exception, the Application.ThreadException handler will catch all
uncaught exceptions from any form/control event handlers.
| What this does is to open a form on another thread to
| stop it blocking the main window. It does this as follows
Why are using Form.ShowDialog on a second thread?
I would simply use Form.Show on the main thread.
Public Sub ShowVehicle(StockNo)
Dim frm As New ViewVehicleStatus(StockNo)
frm.Show()
End Sub
| However, the no of handles just keeps increasing - I presumed that
| the garbage collector should tidy up every now and then,
| but thats not what I'm seeing.
When the user closes a form opened with Show, it will automatically call
Dispose when it is closed. When the user closes a Form opened with
ShowDialog, you need to be certain to call Dispose... Yes the GC will
eventually, at its descrition, call Finalize on the Form, however this may
be long after all the handles have been consumed...
Hope this helps
Jay
"Simon Verona" <ne**@aphroditeuk.com> wrote in message
news:u2**************@TK2MSFTNGP12.phx.gbl...
I have a problem in my application which I believe is due to open handles..
..
The symptom that users report is that after they have been using the
application for a while, it will randomly just crash with an exception
report (I've not got the details of the error, but I'm working on that
now!).
I'm trying to reproduce the circumstances by simulating a typical batch of
user tasks on my pc and monitoring whats happening. I'm guessing it's some
problem with threads/handles or something so I've opened up the task manager
and added all the available columns.
What I've noticed is that whilst the application is running, the memory
usage keeps increasing, but more worrying, the no of open handles just keeps
going up and up (it's nearly 4000 handles after running through about 30
tasks).
What the application is doing is as follows:
I have a main form showing, which displays a list from a database.
Then what I'm doing is clicking down the list one by one..
What this does is to open a form on another thread to stop it blocking the
main window. It does this as follows
=====
Private sub Click(rowno as int32)
dim vehicle as new dmsvehicle.vehicle
vehicle.showvehicle(Data(rowno))
end sub
=====
The Vehicle.showvehicle subroutine is as follows:
====
public sub ShowVehicle(StockNo)
Dim frm As New ViewVehicleStatus(StockNo)
Dim t As New Threading.Thread(AddressOf frm.dmsShowDialog)
'frm.StockNo = StockNo
t.Start()
end Sub
====
The "dmsShowDialog" subroutine in the form is simply doing a me.showdialog.
This all seems to work fine, and when I close the form I see a message such
as "The thread '<No Name>' (0x6ec) has exited with code 0 (0x0)." appear in
the output window of the development environment.
However, the no of handles just keeps increasing - I presumed that the
garbage collector should tidy up every now and then, but thats not what I'm
seeing.
I've not actually duplicated the users issue yet (but I have a high spec
machine with masses of memory), but I suspect that this will be the cause of
their problem?
Any suggestions as to what I've done wrong?
Thanks in advance
Simon