I have a windows service that calls a page after a certain interval of time. The page in turn creates some reports. The problem is that the service stops doing anything after 2-3 calls. as in it calls the page for 2-3 times and then does not do any work though it shows that the service is running…i am using timers in my service.. please can someone help me with a solution here thank you
the code:(where t1 is my timer)
protected override void OnStart(string[] args) { GetRecords(); t1.Elapsed += new ElapsedEventHandler(OnElapsedTime); t1.Interval = //SomeTimeInterval t1.Enabled = true; t1.Start(); } private void OnElapsedTime(object source, ElapsedEventArgs e) { try { GetRecords(); } catch (Exception ex) { EventLog.WriteEntry(ex.Message); } } public void GetRecords() { try { string ConnectionString = //Connection string from web.config WebRequest Request = HttpWebRequest.Create(ConnectionString); Request.Timeout = 100000000; HttpWebResponse Response = (HttpWebResponse)Request.GetResponse(); } catch (Exception ex) { } }
I think you’re missing something about disposing your objects like StreamReader, WebRequest, etc.. You should dispose your expensive objects after using them.