title: Threads in Windows Service and lack of Ram Memory
body: <p>I'm making the windows service to get Account Information From Bank; My Service works well, but After some days(8 or more days) it uses more than 7 Gigabytes of RAM.(With 6 or 7 Threads);</p>
  
  <p>Here is my Code:</p>
  
  <pre><code>private Thread MainThread;
  
          protected override void OnStart(string[] args)
          {
              try
              {
                  ThreadStart starter = new ThreadStart(() =&gt; ConfigurationService());
                  MainThread = new Thread(starter);
                  MainThread.Start();
                  // Event Started
              }
              catch (Exception ex)
              {
              }
          }
  
          protected override void OnStop()
          {
              MainThread.Abort();
              EventLog.WriteEntry("Service Aborted", EventLogEntryType.Information);
          }
  </code></pre>
  
  <p>And Here is My Method Which Decides Which Day(s) information must receive;</p>
  
  <pre><code>private void ConfigurationService()
  {
      serv = new ServiceSoapClient();
      serv.Endpoint.Binding.CloseTimeout = serv.Endpoint.Binding.OpenTimeout = serv.Endpoint.Binding.ReceiveTimeout = serv.Endpoint.Binding.SendTimeout = TimeSpan.FromSeconds(30);
  
      DateTime startTime = DateTime.Parse(@"2012/05/20");
      while (true)
      {
          try
          {
              Thread.Sleep(TimeSpan.FromMinutes(1));
              double days = DateTime.Now.Subtract(startTime).Days;
              if (days &gt; 30)
              {
                  GetDataFromBank(startTime, startTime.AddDays(30)); 
                  startTime = startTime.AddDays(31);
              }
              else
              {
                  GetDataFromBank(startTime, startTime.AddDays(days));
                  startTime = startTime.AddDays(days);
              }
  
          }
          catch (Exception ex) { }
      }
  }
  </code></pre>
  
  <p>And Here is The Main Method (Thread to Receive Data from Bank) : </p>
  
  <pre><code>private void GetDataFromBank(DateTime fromDT, DateTime toDT)
  {
      ThreadPool.QueueUserWorkItem(new WaitCallback((o) =&gt;
      {
          try
          {
              while (true)
              {
                  if (fromDT &gt; toDT)
                      break;
                  try
                  {
                     // Call The Bank Service
                     // Receive Transaction related to Specified Date
                     // Compare with Database if not Exist Add To Database
                      }
                  }
                  fromDT = fromDT.AddDays(1);
              }
          }
          catch (Exception ee)
          {
              EventLog.WriteEntry(ee.Message, EventLogEntryType.Error);
          }
      }));
  }
  </code></pre>
  
  <p>The service Works well and Receive All Information from StartDate untill EndDate;
  after almost 1 hour the service just Check the CurrentDay every minutes and in TaskManager i  see 5 or 6 Active Thread and Memory usage Equal 24 Megabytes;</p>
  
  <p><strong>Question :</strong> Why Does The Service use more than 7 Gigabytes of RAM after some days?</p>
  
  <p>Thanks in advance</p>
  
  <p>Edit ===========</p>
  
  <p>I forgot telling you I never turn off the Computer.</p>