Windows application terminates (exits) abnormally

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello!

I am having a problem with a windows application that abnormally terminates
itself. The application is a multi threaded .NET 1.1 application, and can
briefly be described as follows:

Call the thread running the GUI "A". When user clicks a button a new thread
"B" is created and started. "B" does a lots of work, among others transmitts
data via a USB-CAN-interface. At the end of "B" a paper label is printed
using methods provided by the framework
(System.Drawing.Printing.PrintDocument)

If I removes the printing routines no error occures, but when the printer is
enabled the application sometimes terminates. No error codes, no unhanlded
exceptions, no messages.

Does anyone have a clue what causes this problem?

Regards, Daniel
 
Hi Daniel,

..NET Framework versions earlier than 2.0 swallow exceptions that occur on
background threads.

I suggest wrapping your printing code in a try..catch block. Read the
documentation for the printing methods that you use to determine which
exceptions may be thrown and catch the ones from which your application can
recover.

To aid in debugging, you may want to add a try..catch-all exception handler
that logs any exception and then rethrows them (even those exceptions not
being handled in your code).
 
Hello!

Thank you for a quick reply! Actually there are commonly no errors when
printing the label. Sometimes the error occures here, but not all the time.
Very often the error occures when user starts "B" agin.

I have try-catch blocks around my printing code, around the thread start
method and even around Main, no exceptions are thrown (At least no managed
exceptions). I also loggs all threads via Application.ThreadException and
Application.ThreadExit. As I can se, the printing thread (whicth is straed by
the framework) exits normally.

Another strange this is that in some cases the entire computer is
restarted...!

Daniel Carlson
 
Hi Daniel,

That does sound bad :|

Maybe it's a driver error.

The other thing I can recommend is to search the newsgroups and Microsoft's
knowledge base for problems like yours (if you haven't already) and then
solicit the help of Microsoft if that doesn't help you to solve the problem.

GL!
 
The framework 1.1 has an issue where it sometimes isnt ale to convert an
Access Violation into a .NET exception to throw and therefore the CLR is
terminate immediatly by windows without 1 more line of code running. I had
this for a long time with a data access rountine which would sometimes make
the application just dissappear like it was killed in task manager, I used to
have a link to the KB article about it but this was about 3 years ago now so
thats long gone.
Try handling System.Windows.Forms.Application.ThreadException event to see
if thats fired. Secondly, try running the thread inside a new app domain and
handling the unhandled exception event on the app domain from the form. It be
that the AppDomain is kill rather than the whole process.
I remember this one being a killer.

Ciaran O'Donnell
 
Thank you for this post! This is the first post that is helpful to me! I have
search for infomration for over one week now...

I handle the System.Windows.Forms.Application.ThreadException event with no
result. No exceptions are thrown. I will try to run my application from
another domain and see what that gives.

A question though: Do you think this is solved in 2.0 of the framework? Or
at least give me a more stabel termination?

Daniel Carlson
 
I have never had it happen on 2.0 and think I remember something about it
being sorted in 2.0. I have been building a big Winforms app in 2.0 for the
last year and it hasnt happened to me once.

Ciaran O'Donnell
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top