3

I have a windows c# program (.net 3.5) that runs in the background on a real time controller (Windows 7 Embedded).

After a few days the process apparantly terminates. Now I am thoroughly logging the actions and exceptions of my program. Everything that can throw an exception is surrounded by try/catch and is being writting to a log file, and if the logger has an exception that is written to the windows event log.

But there is nothing in the logs that hints to an exception that could cause a program termination.

Are there other techniques to catch and log program termination?

So far I couldn't reproduce the bug in an online debug session.

The program itself is very simple. It uses two stopwatches and spawns a thread to communicate with a real time program. It writes an 'alive' boolean, an 'error' integer and reads another integer. The log file size is limited to 10 MBytes. If the size is reached, the file is renamed with a date and a new file is opened. Files older than 30days will be deleted.

I have checked the windows event logs and couldn't find anything that directly relates to the program.

What would you do?

Simorgh
  • 61
  • 1
  • 11
  • 2
    Look at global exception handler, mayby it can catch something. – BWA Oct 09 '17 at 09:28
  • @BWA Agree, that would be my suggestion too. – rmjoia Oct 09 '17 at 09:31
  • Possible duplicate of [How to catch ALL exceptions/crashes in a .NET app](https://stackoverflow.com/questions/82483/how-to-catch-all-exceptions-crashes-in-a-net-app) – Sinatr Oct 09 '17 at 11:49
  • Technology is also important: [winforms](https://stackoverflow.com/a/46582236/1997232), [wpf](https://stackoverflow.com/a/1472522/1997232), etc. – Sinatr Oct 09 '17 at 11:52

2 Answers2

1

I could my answer my own question.

Unfortunately I left out a detail in my question which I deemed irrelevant. The application is started by the windows task scheduler at system boot before any user logs in. There is a checkbox at the task properties that terminates the task if it takes longer than 3 days. I forgot to uncheck it :(.

Thank you for your contributions.

Simorgh
  • 61
  • 1
  • 11
0

The best approach for you would be to consider the global exceptions. You can Catching the First Chance Exceptions which will catch every exception that occurs in your application which can be done as simply as adding the following piece of code:

AppDomain.CurrentDomain.FirstChanceException += (sender, eventArgs) =>
{
    Debug.WriteLine(eventArgs.Exception.ToString());
};

Also for more details about handling the global exception you can refer to this really helpful article.

Tayyab
  • 1,207
  • 8
  • 29