473,405 Members | 2,272 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Windows Service restart on exception

Hello
I'm building a windows service that grabs information from a website periodically, and the goal is to start all over again, when finding an exception, for example when internet disconnects.
Any help would be appreciated.
Code below
Expand|Select|Wrap|Line Numbers
  1. public string cadena(string pagina)
  2.         {
  3.             try
  4.             {
  5.                 String cadena;
  6.                 WebRequest myWebRequest = WebRequest.Create(pagina);
  7.         myWebrequest = 10000;
  8.                 WebResponse myWebResponse = myWebRequest.GetResponse();
  9.                 Stream ReceiveStream = myWebResponse.GetResponseStream();
  10.                 Encoding encode = System.Text.Encoding.GetEncoding("ISO-8859-1");
  11.                 StreamReader readStream = new StreamReader(ReceiveStream, encode);
  12.                 cadena = readStream.ReadToEnd();
  13.                 readStream.Close();
  14.                 myWebResponse.Close();
  15.                 return cadena;
  16.             }
  17.             catch (WebException error)
  18.             {
  19.                 myTimer.Enabled = true;
  20.                 return "error";
  21.             }
  22.         }
  23. public void inicia(object sender, System.Timers.ElapsedEventArgs e)
  24.         {
  25.                 myTimer.Enabled = false;
  26.                 String strSite = cadena("www.something.com");
  27.                 myTimer.Enabled = true;            
  28.         }
  29. protected override void OnStart(string[] args)
  30.         {           
  31.                 myTimer = new System.Timers.Timer();                    
  32.                 myTimer.Interval = 1500;         
  33.                 myTimer.Elapsed += new System.Timers.ElapsedEventHandler(inicia);      
  34.                 myTimer.Enabled = true;            
  35.         }
May 21 '09 #1
1 2702
tlhintoq
3,525 Expert 2GB
@alexdrack
Any help with what exactly? You haven't described any problems you are encountering
May 21 '09 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Ciaran | last post by:
Hi All, I have created a Windows Service. In the event of an Exception occuring I would like to notify Windows to restart the service as shown below: <snip> protected override void...
0
by: Tom J | last post by:
I have this code: System.ServiceProcess.ServiceController sc = new System.ServiceProcess.ServiceController("MyService"); if(sc.Status == System.ServiceProcess.ServiceControllerStatus.Stopped)...
14
by: iceman | last post by:
Hello, I have a windows service. I want to restart it after every 24 hour. Is it possible to restart the service programmatically(from the service itself) using the sercvice controller object?...
3
by: Richard | last post by:
I have created a Windows service which performs various functions including setting variables in other application objects. When the service runs under Local System account the functionality all...
1
by: Sergey Krutous | last post by:
Can you please help me to resolve the following issue: I developed a windows service. At start up (I have overriden OnStart method) it connects to a web service and if the connection fails the...
7
by: shai | last post by:
I am working at .net 1.1, writing in c#. I have windows service with a COM object. Every unexpected time The COM object throw an error that make my service get stuck (do not respond). I can catch...
6
by: sergio.calleja | last post by:
Hi Everybody, i need to restart a windows service made with c# when an fixed event is raised. So to test it, I've added a servicecontroller to my service, and in the creation method, i've created...
1
by: ropo | last post by:
I have a class library used by a windows service executable, both binaries and dependancies are in one bin directory located on c:. 1) I can run a test app on my class library without failure 2)...
0
by: pratika2002 | last post by:
Hi, I am having a windows service project which is built by someone else and I have to understand the fuctionality. While running the service I am getting the following exception. "An unhandled...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.