none
C#: Handle count is getting increased RRS feed

  • Question

  • Hi,

    I have developed an application in C# that is doing some database operations.

    I am calling a method that is doing DB operation inside infinite do while loop and pausing the application for 1 second using Thread.Sleep(1000).

    When I left the application running for 2 or more days then I came to know that handle count(Displayed in Task Manager) has increased about 40000 and its growing contineously...

    Below is the sample code that I am using in my application:

    private static void Process()
                {
                    try
                    {

                        do
                        {
                            if (oCon.State == ConnectionState.Closed || ((int)DateAndTime.DateDiff("n", DateTime.FromOADate(gDtHrConect), DateTime.Now, FirstDayOfWeek.Sunday, FirstWeekOfYear.Jan1)) >= 20)
                            {
                                fReCon();
                            }

     
                            DoSomeDbOperation();
          
                            Thread.Sleep(1000);

                        }
                        while (true);
                    }
                    catch
                    {
                    }
                }

    Please suggest why handle count is increasing? is this issue related to Threading?

    high valume of Handles can create problem in the application?

    Please do let me know if you need further details on this.

    Thanks for your help.

    Tuesday, February 3, 2015 10:14 AM

All replies

  • Have you run the posted code to determine that it is causing the issue? I don't see anything in the posted code that would cause the handle count to increase. Please let us know exactly which instruction is causing the problem.  Comment out sections of the code to help determine where the issue is occurring.

    jdweng

    Tuesday, February 3, 2015 10:29 AM
  • Hi,

    Below is the current situation in my application:

    1. Handle count is increasing but memory is stable, no increase in memory.

    2. I have used COM component that is doing some operation, could it cause handle count increase?

    3. what could be the issue if the handle count is getting increase constantly?

    Even I don't know which portion of the code is casuing handle issue.

    Thanks

    Tuesday, February 3, 2015 11:19 AM
  • Hello Pramod,

    You could follow the suggestion from Joel, you could firstly comment out the “DoSomeDbOperation()” method to see if it then would work find without increasing the handle count. This would help narrow down this issue.

    And with your description, this issue seems to be a handle leak, then you could also check this blog below which would help you find what type handles leak:

    How to troubleshoot a handle leak

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, February 4, 2015 2:38 AM
    Moderator
  • Thanks for your suggestion.

    I would say one more point about this application we have used the static classes..will this create the problem in handle count increase since this application is running for long time or can say infinite mode until we close it manually.

    Wednesday, February 4, 2015 3:33 AM
  • Hello Pramod,

    >>will this create the problem in handle count increase since this application is running for long time or can say infinite mode until we close it manually.

    I am not sure since it is not clear how you wirte the code, i do suggest you could have a try and have you tried with the suggestions mentioned by Joel, comment out some called method to narrow down this issue?

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, February 10, 2015 8:17 AM
    Moderator