Windows Service restart on exception

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • alexdrack
    New Member
    • May 2009
    • 1

    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
    Code:
    public string cadena(string pagina)
            {
                try
                {
                    String cadena;
                    WebRequest myWebRequest = WebRequest.Create(pagina);
    		myWebrequest = 10000;
                    WebResponse myWebResponse = myWebRequest.GetResponse();
                    Stream ReceiveStream = myWebResponse.GetResponseStream();
                    Encoding encode = System.Text.Encoding.GetEncoding("ISO-8859-1");
                    StreamReader readStream = new StreamReader(ReceiveStream, encode);
                    cadena = readStream.ReadToEnd();
                    readStream.Close();
                    myWebResponse.Close();
                    return cadena;
                }
                catch (WebException error)
                {
                    myTimer.Enabled = true;
                    return "error";
                }
            }
    public void inicia(object sender, System.Timers.ElapsedEventArgs e)
            {
                    myTimer.Enabled = false;
                    String strSite = cadena("www.something.com");
                    myTimer.Enabled = true;            
            }
    protected override void OnStart(string[] args)
            {           
                    myTimer = new System.Timers.Timer();                    
                    myTimer.Interval = 1500;         
                    myTimer.Elapsed += new System.Timers.ElapsedEventHandler(inicia);      
                    myTimer.Enabled = true;            
            }
  • tlhintoq
    Recognized Expert Specialist
    • Mar 2008
    • 3532

    #2
    Originally posted by alexdrack
    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
    Any help with what exactly? You haven't described any problems you are encountering

    Comment

    Working...