Click here to Skip to main content
15,891,431 members
Please Sign up or sign in to vote.
2.00/5 (2 votes)
Hi,

I have a windows application(UI) and a windows service.This windows application continuously calls methods in the windows service and the service does its work accordingly.The communication between UI and service is achieved by .Net remoting.


As per my application requirement, the UI should call service methods in different durations(for ex. every 1 minute) and this process should continue for 3 days(may be greater than this).

But UI is able to call methods of service for ~10-12 hrs and then UI hangs up. After I coming to office in next morning "client not working" message box is displayed with "Debug" and "Close" buttons .Once I clicked on debug which is just displaying "StackOverflowException" and no other details.

Then I started removing unnecessary objects in my code and disposing objects.Then also no use.

Please give your valuable suggestions.

Added below sample code part on 17-Nov-2014:

Adding my hunch for this problem below, please review and update my guess is correct or not.


C#
public void XXX()
{
  //Variable declaration ->10 variables(consists string,int,bool variables) 
  try
  {
    //two integer variable declaration
     TreeList selectedTreeList = (TreeList)oTabPage.Controls[0]; // treelist type is  DevExpress.XtraTreeList.TreeList 
                  
                  foreach (TreeListNode scenarioNode in selectedTreeList.Nodes)
                  {
                     
                     //Some operations
                        /* Some lines of code to perform business=>which uses newly created ~4-5 variables used in the scope*/
                     //One special case
                     if(special condition)
                     {

                     //Some lines of code to do some operations for this special     case(includes ~2-3 variable declaration)
                      
                       XXX();
                       break;
                     }
                    /* Some lines of code and also includes calls to service */
                    
                   Thread.Sleep(60000);
                   }
     //10-15 lines of code
    
  }

  catch(Exception ex)
  {
   //logging code

  }



}


Here is my suspicion:

In main method XXX(), we are calling XXX(). Like that we call XXX() in another XXX() and it goes on.This process is infinite.So each time when we call XXX(),
new variables are created and some space is allotted to them in RAM.

Note:In each XXX() method, it will take 5 minutes to enter into special condition and then calls XXX().(Assume that after 5 iterations in foreach it enters into special condition)

Shortly, I can say this whole thing as never ending recursion.


So scope of each XXX() method never ends.Hence garbage collector will not try to clear memory.So that total RAM will be filled and get StackOverflowException and then hang.


Please give your inputs.

Thanks and Regards,
Anil
Posted
Updated 18-Nov-14 20:13pm
v3
Comments
PIEBALDconsult 12-Nov-14 22:48pm    
You would have to show us some of the code. You must be instantiating more and more of some class and not disposing it. There are many ways this can happen.
Aside from that, a GUI application should generally not be left running for extended periods, that's generally the purpose of a Windows Service.
Anil Vittal 17-Nov-14 5:16am    
Hi,
Thank you for your suggestions.
I added sample code/pseudo code for your reference as well as my hunch for the problem.

Please review.

Thanks and Regards,
Anil
Sergey Alexandrovich Kryukov 12-Nov-14 23:00pm    
Due to good weather, my access to your hard drive is somewhat limited, and all our magicians are on vacation. So, you can only get very general answer. :-)
—SA
george4986 12-Nov-14 23:58pm    
good or bad weather? ;-)
Sergey Alexandrovich Kryukov 13-Nov-14 1:10am    
It's fine. :-)
—SA

Please see my comment to the question. So, very general ideas:



Good luck.
—SA
 
Share this answer
 
v2
Comments
Anil Vittal 17-Nov-14 5:22am    
Hi Sergey,

I am glad!!, you took time to help me:) Thanks for your comments.They will definitely help.

For your reference,today I added some pseudo code of my logic and hunch for the problem.Please review.


Thanks and Regards,
Anil
Sergey Alexandrovich Kryukov 17-Nov-14 11:14am    
You see, never ending recursion is not a problem. If you can reproduce it under the debugger, you can easily dig out a bug. Basically, you go at the point where execution repeats and look at the debug window "Call stack". Few iterations at worst case; and you find the root cause. Anyway, stack overflow exception almost always is the indication of never ending recursion or multiple recursion.

If you cannot reproduce it, that is the problem. Do I understand you right: it happens only after hours of work? Anyway, you have a chance to detect it, because, according to your description, the problem happens on the click. It makes things easier. You can run it all under the debugger, and, before the click, put a break point on some "strategically chosen points". Apparently, one of them would be the very beginning of your XXX...

—SA
Anil Vittal 18-Nov-14 10:17am    
So I keep long run under debugger and put break point in "catch" block to catch the appropriate exception.I will look for the exception on next day morning.By the way, for which thing I have to pay attention in "Call stack" window when debugging.I never paid attention in my experience for this window.Please give me an overview on using that window and whats the critical information we can find out and how it is useful.Thank you for your inputs.
Sergey Alexandrovich Kryukov 18-Nov-14 11:59am    
Do you know how a call stack works? You have to, even at the CPU level. All calls (as well as passing method parameters and local variables) are based on stack, so it's supported directly by the CPU. This debug window finds all lines of code through which the current line of code was reached through the stacks of all calls, from the very beginning. I think this should be clear.
—SA
Anil Vittal 28-Nov-14 0:45am    
Hi SA,

Thank you for your comments.My priority was different for these days.Working on this.Will update you the results with my experiments.
You are trying to periodically invoke a windows service periodically through a UI appl. Is there a reason why you opted for windows application (UI). Why don't you convert this to a console app.
 
Share this answer
 
Comments
Anil Vittal 17-Nov-14 7:28am    
Hi Sathish,

Basically that is my application requirement. UI is there for controlling runs.
User opens a script and runs it for the time he requires.Then he stops.He can also create new scripts using UI and performs runs.In between if he does not satisfy with the values ,then he stops it and then changes values and performs run.That script execution time
depends on his requirement.He may opt for infinite time(if script need to run for long time).So it runs on weekend and next week morning he simply stops it and analyzes the results.In this process my UI hanging up.

Note:So in a run, my windows service is called periodically from UI to pass data present in the script.Service performs required things for given data.

Thanks and Regards,
Anil

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900