12 Replies - 948 Views - Last Post: 08 April 2012 - 12:42 PM Rate Topic: -----

#1 rg2720  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 22
  • Joined: 14-February 12

Program works well for some hours, then freezes

Posted 04 April 2012 - 04:27 AM

Hello people,

Firs of all: I am aware that it is IMPOSSIBLE for you guys to tell me what's wrong with my program.

What I am wondering is if any of you have tips and ideas for me as to how I can find the problem. I am not great at using the debugging functionality (using Visual C# 2010 Express).

But as the title says: The program works fine to start off with but then it freezes completely and I have to stop it using "Stop debugging" in Visual Studio. It is a program receiving serial data and the data shows up perfectly for a while but I may return after a couple hours only to find a frozen application.

Since it's not a compiling error and I don't get anything from the exceptions I find it very hard to debug. I am using a USB->Serial converter - do you think it is the USB port that resets from time to time?

Any help is GREATLY appreciated :)


Thanks,
Rg2720

Is This A Good Question/Topic? 0
  • +

Replies To: Program works well for some hours, then freezes

#2 Sergio Tapia  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1212
  • View blog
  • Posts: 4,128
  • Joined: 27-January 10

Re: Program works well for some hours, then freezes

Posted 04 April 2012 - 05:25 AM

Check the memory usage in the process explorer when you start the application, and then once it is frozen. Your app might freeze, but it will still show up in process explorer.

Maybe you have a memory leak somewhere?
Was This Post Helpful? 1
  • +
  • -

#3 rg2720  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 22
  • Joined: 14-February 12

Re: Program works well for some hours, then freezes

Posted 04 April 2012 - 06:17 AM

View PostSergio Tapia, on 04 April 2012 - 12:25 PM, said:

Check the memory usage in the process explorer when you start the application, and then once it is frozen. Your app might freeze, but it will still show up in process explorer.

Maybe you have a memory leak somewhere?


Thanks for your reply! The program has now been running since 12:20 and the time here is now 15:14 (3.14pm) and everything seems to be working fine.

Task Manager shows memory usage of 105-125MB (varying). So it seems to me that memory leakage is not the problem? I will check again later if (when) the program freezes.

I could also post the code, but it is 1012 lines of code...
Was This Post Helpful? 0
  • +
  • -

#4 Ryano121  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1055
  • Posts: 2,234
  • Joined: 30-January 11

Re: Program works well for some hours, then freezes

Posted 04 April 2012 - 06:20 AM

*
POPULAR

You might want to try putting in some

Debug.WriteLine's

for every major task that you program does. That way when it freezes you at least have some idea of what the program is supposed to be doing at that point.
Was This Post Helpful? 5
  • +
  • -

#5 Sergio Tapia  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1212
  • View blog
  • Posts: 4,128
  • Joined: 27-January 10

Re: Program works well for some hours, then freezes

Posted 04 April 2012 - 06:21 AM

Wait until it freezes then check the memory, maybe the leakage happens later.
Was This Post Helpful? 2
  • +
  • -

#6 negligible  Icon User is offline

  • D.I.C Regular

Reputation: 62
  • View blog
  • Posts: 302
  • Joined: 02-December 10

Re: Program works well for some hours, then freezes

Posted 04 April 2012 - 06:28 AM

If you're memory isn't being physically filled up it could be a problem with Garbage Collection in the managed code, in a nutshell this means that although memory is available it is not being reallocated for actual use.

I found these blogs very useful when learning to deal with memory issues. They helped me narrow down my problem and rule things out.

http://blogs.msdn.co.../10/279612.aspx
http://blogs.msdn.co...b-3-memory.aspx

You may also be able to find some helpful information or resources in my old question thread, some more links to guides I was using and stuff there.

This post has been edited by negligible: 04 April 2012 - 06:30 AM

Was This Post Helpful? 1
  • +
  • -

#7 rg2720  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 22
  • Joined: 14-February 12

Re: Program works well for some hours, then freezes

Posted 05 April 2012 - 01:18 AM

Thanks a lot people.

I have since yesterday been working on all your suggestions and will continue to do so.

I added some
Debug.Writeline
s and after the program froze I have some interesting facts:

* The Server.Vhost program in Task Manager (Server is my app) is now leaking. Currently at 237MB and rizing slowly.

* The Debug.Writeline's are STILL outputting fresh data to the Output window, even though my program is frozen to the point that I can't open in; i.e. nothing happens when I push the icon on the task bar.

* I see in the Output that the program entered a function in a thread and never returned from it (even though it had returned from it hundreds of times before the application froze.


Thanks again for all your help. I will continue debugging this, but if you guys see something that might help or have any other comments I would be happy to read them! :)

-Rg2720
Was This Post Helpful? 0
  • +
  • -

#8 JackOfAllTrades  Icon User is online

  • Saucy!
  • member icon

Reputation: 5672
  • View blog
  • Posts: 22,527
  • Joined: 23-August 08

Re: Program works well for some hours, then freezes

Posted 05 April 2012 - 04:44 AM

Debugging Tutorial
Was This Post Helpful? 1
  • +
  • -

#9 rg2720  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 22
  • Joined: 14-February 12

Re: Program works well for some hours, then freezes

Posted 06 April 2012 - 03:31 AM

View PostJackOfAllTrades, on 05 April 2012 - 11:44 AM, said:



Thanks for that, but I do know the very basics of debugging covered in that tutorial. However, that is of minor help to me as long as the program works perfectly for hours before crashing. I guess the way forward would be adding loads of Console.Writeline to show exactly where the program was when it stopped responding...
Was This Post Helpful? 0
  • +
  • -

#10 JackOfAllTrades  Icon User is online

  • Saucy!
  • member icon

Reputation: 5672
  • View blog
  • Posts: 22,527
  • Joined: 23-August 08

Re: Program works well for some hours, then freezes

Posted 06 April 2012 - 04:16 AM

You might consider, instead of Console.WriteLine, some sort of logging library or writing to a file. You'll get more history.
Was This Post Helpful? 1
  • +
  • -

#11 eclipsed4utoo  Icon User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1511
  • View blog
  • Posts: 5,916
  • Joined: 21-March 08

Re: Program works well for some hours, then freezes

Posted 06 April 2012 - 07:22 AM

Does the user move between screens in the application, or does it just sit on one screen the entire time?

In an early project I worked on, we had a similar problem. The application would run for like 15 hours without problems, then it would hang the PC. In the end the problem ended up being that our application was consuming all of the window handles that Windows could generate. Once Windows can't create anymore handles, it hangs.

How did we do this? We weren't closing forms when the user was moving between them. So each form was staying in memory, along with the window handles for all of the controls on the form.
Was This Post Helpful? 1
  • +
  • -

#12 rg2720  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 22
  • Joined: 14-February 12

Re: Program works well for some hours, then freezes

Posted 08 April 2012 - 12:21 PM

View PostJackOfAllTrades, on 06 April 2012 - 11:16 AM, said:

You might consider, instead of Console.WriteLine, some sort of logging library or writing to a file. You'll get more history.


Do you have one you would recommend?

I have now found that I DO have a memory leak. From Google I've found that the CLR profiler may be helpful, would you agree with that?

View Posteclipsed4utoo, on 06 April 2012 - 02:22 PM, said:

Does the user move between screens in the application, or does it just sit on one screen the entire time?
(...)


The program is a server program that communicates with two serial line interfaces, as well as showing webcam images etc. The GUI is just ONE window, but split with tabPages.

If you guys want pictures of the GUI or code in order to see the problem more clearly, let me know and I'll provide it.
Was This Post Helpful? 0
  • +
  • -

#13 Sergio Tapia  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1212
  • View blog
  • Posts: 4,128
  • Joined: 27-January 10

Re: Program works well for some hours, then freezes

Posted 08 April 2012 - 12:42 PM

I would recommend using NLog to keep logs on what is happening at every step of the way.

It also has a NuGet package if you want to install it that way.

Trace your steps at every move and you'll pin point where things stopped moving.

This post has been edited by Sergio Tapia: 08 April 2012 - 12:44 PM

Was This Post Helpful? 3
  • +
  • -

Page 1 of 1