0

I am developing an application in Visual C# using winforms.

The application is basically a screen with three tabs. It shows values from processes running on the system per second (using System.Diagnostics.Process[] ).

It generates and updates lot of numbers and calculations (around 4000/second). But after 10000 iterations or ~45 minutes of work, it just crashes and the amazing part is It always crashes around the same time.

The RAM involved here is just 70mb and CPU load never goes above 35% for the app under windows xp and windows 7. The aim of the app is to allow users to view processes running on the system with the cpuload and memory load. we cannot suggest taskmanager due to security reasons.

The error is not trapped by C# by any of the try - catch methods

Following screens are a sample that follow after the crash

enter image description here

The main application screen looks like this

enter image description here

Has anybody faced such a situation where the app crashes after a fixed run length.

Please suggest a diagnostic tool or a method to trap such errors.

Thanks for the replies

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
arvind
  • 1,385
  • 1
  • 13
  • 21
  • Have you checked for any memory leaks ? and do you have any code smaple ? – JohnnBlade Jul 20 '12 at 06:12
  • it is just a timer that runs a infinite loop that gets all processes and shows in a grid. like do { Process[] plist = Process.GetProcesses(); } while(true); Memory leak (even larger applications run fine, plus it always crashes after a fixed run) . BTW your blog at wordpress is good. – arvind Jul 20 '12 at 06:16
  • With timer you don't mean the timer object right, have you tried using the timer object instead of using an infinite loop. Thnx i try to update my blog as much as i can – JohnnBlade Jul 20 '12 at 06:22
  • 1
    and do you also use threading for example a backgroundworker – JohnnBlade Jul 20 '12 at 06:24
  • 1
    It is hard to say what is the cause. if it crashes after specefic itteration then it mihgt be some out of array index or something. paste some of the code you think it might be the problem, specially yout timier code – Dumbo Jul 20 '12 at 06:24
  • Does the same happen when you have the debugger attached? – leppie Jul 20 '12 at 06:30
  • 1
    http://blogs.msdn.com/b/lexli/archive/2009/08/23/when-the-application-program-crashes-on-windows.aspx – Lex Li Jul 20 '12 at 06:47
  • the link mentioned above has changed to http://www.microsoft.com/en-us/download/details.aspx?id=26798 – arvind Jul 20 '12 at 08:15

2 Answers2

4

If you have Visual Studio installed on this machine, you should be able to debug the application, when it crashes. At least you should see which exception is thrown and where.

In my application I have a handler, which catches uncatched exceptions and writes them to a logfile.

Add to the constructor

AppDomain currDomain = AppDomain.CurrentDomain;
currDomain.UnhandledException += new UnhandledExceptionEventHandler(UnhandledExHandler);

and add also this handler

private void UnhandledExHandler(object sender, UnhandledExceptionEventArgs args)
{
    Exception e = (Exception)args.ExceptionObject;
    // Log the exception here
}
Simon
  • 1,616
  • 2
  • 17
  • 39
4

Try adding this into your service in the main void

AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;

        public static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
        {
            // do your logging here, write to a file, or send an email
        }

and

service.ExceptionThrown += service_ExceptionThrown;

        private static void service_ExceptionThrown(object sender, ExceptionThrownEventArgs e)
        {
            // do your logging here, write to a file, or send an email
        }

and if you want to debug your service in visual studio then just add -d by start up option in the Command line arguments

Command line argumnets

JohnnBlade
  • 4,261
  • 1
  • 21
  • 22
  • @johnblade : i used a timer the loop just loops over all the processes like foreach(Process p in plist) { } . Yes i tried using backgroundworker as well. and even put thread.sleep(1000) just to slow it down a bit. Are there any tools that just point in some way to the errors. I have downloaded the CLR profiler, but oh god it looks one needs a whole week to operate it. (there aren't any data saves or data tables) – arvind Jul 20 '12 at 07:44
  • Are you able to get it to run in visual studio with the -d argument ? – JohnnBlade Jul 20 '12 at 07:48
  • i have set the -d option and do i need to run it within visual studio . I will place the event handlers (i think i need to place them in program.cs) – arvind Jul 20 '12 at 07:49
  • 1
    my events are in the static main function, add them there – JohnnBlade Jul 20 '12 at 07:59
  • it seems to be all-right when it is run from visual studio, it is just total confusion now. and crashes when run standalone. i guess i will run more tests. i wish i had a magic wand or a jinn – arvind Jul 20 '12 at 10:22
  • i have marked it as answer because, it has set the track for me to diagnose more. I would recommend http://www.microsoft.com/en-us/download/details.aspx?id=26798 Application that seems to be helpful. thanx to all for replies – arvind Jul 21 '12 at 14:30