0

I am having the console application which creates the PDF for a set of records. For if the count is 9000 above an error occurred that "Error creating window Handle". In the application level i am using 6 threads.

As i observed in the Task Manager the Handles are increasing and the user objects are also increasing.

I have written the obj.Dispose method where ever i have created the object. So now my question is how to decrease the user objects and Handles.

I am using the console application with 3.5 Framework in C#.

Update:

Below is the code which i have used

Thread FirstTreadPDFs = new Thread(() => objPDFsProcess.DoGeneratePDFsProcess());

FirstTreadPDFs.Start();

//Thread2 Thread SecondTreadPDFs = new Thread(() => objPDFsProcess.DoGeneratePDFsProcess()); SecondTreadPDFs.Start();

//Thread3 Thread ThirdTreadPDFs = new Thread(() => objPDFsProcess.DoGeneratePDFsProcess2()); ThirdTreadPDFs.Start();

//Thread4 Thread FourthTreadPDFs = new Thread(() => objPDFsProcess.DoGeneratePDFsProcess()); FourthTreadPDFs.Start();

//Thread5 Thread FifthTreadPDFs = new Thread(() => objPDFsProcess.DoGeneratePDFsProcess1()); FifthTreadPDFs.Start();

FirstTreadPDFs.Join(); SecondTreadPDFs.Join(); ThirdTreadPDFs.Join(); FourthTreadPDFs.Join(); FifthTreadPDFs.Join();

 DataSet dsHeader1 = new DataSet();
                        //Pending Cusotmers need to get to generate PDFs
                        dsHeader1 = objCustStatementDAL.GetCustStatementdetailsForPDF(IsEDelivery, 1);

                        if (dsHeader1 != null && dsHeader1.Tables.Count > 0)
                        {
                            if (dsHeader1.Tables[0].Rows.Count > 0)
                            {
                                writerLog.WriteLine(DateTime.Now + " Trying to get Pending Records");
                                objPDFsProcess.DoGeneratePDFsProcess2();
                                writerLog.WriteLine(DateTime.Now + " Exit Trying to get Pending Records block");
                            }
                        }
                        dsHeader1.Dispose();

After executing 9000+ records the Exit Trying line is executing and stopping the application.

Where ever i use the object i placed Dispose method.

Vara Prasad.M
  • 1,530
  • 9
  • 31
  • 55

1 Answers1

1

From your question it is not really clear what are you doing, but if I'm guessing right, you are keeping too many open file handlers.

So here it comes. If you open a StreamReader for example, you open a File Handler, what happens to be an unmanaged and limited resource. Unmanaged means the .NET runtime can't keep tabs on its use, and even if you lose reference to the StreamReader object, the handler won't be closed. So for that, you need to call the Dispose function (and if you are creating a class that uses native resources, implement the IDisposable interface, wich contains the Dispose function properly). You can do the calling explicitly, but the best for everyone is to use the using block. That way your handlers will be closed properly everytime you leave the scope of the block, whatever the means.

Of course if you are triing to keep open and use this much handlers, you need to trick your way around it somehow, and that would still involve closing not currently used ones.

Robert
  • 1,658
  • 16
  • 26