Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Need help with my service please!!!

Need help with my service please!!!

Scheduled Pinned Locked Moved Visual Basic
helpcsharpcomsysadminquestion
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    tcombs07
    wrote on last edited by
    #1

    Hey guys the problem that I am is this. I am writting a service that every five minutes goes out and requests a web page. And the problem that I am having is whenever I disconnect my computer for the internet, the service throws an error. I have tried implementing some error handling but I can't seem to figure it out. I would like to code somethingso that if in 30 seconds a response is not gathered then to abort the request and try again in five minutes. Here is the code that i currently have: Imports System Imports System.IO Imports System.Net Imports System.Threading Public Class VirasecHB 'Declare the Thread Private VirasecHB_Thread As New Thread( _ New System.Threading.ThreadStart(AddressOf waitProcedure)) 'Declare Variables Dim serverID As String = "1336" Dim webURL As String = "http://www.virasec.com/intranet/tech/heart/heartdb.asp?hdur=300&hsid=" & serverID Protected Overrides Sub OnStart(ByVal args() As String) ' Add code here to start your service. This method should set things ' in motion so your service can do its work. WebRequestProcedure() VirasecHB_Thread.Start() End Sub Protected Overrides Sub OnStop() ' Add code here to perform any tear-down necessary to stop your service. VirasecHB_Thread.Abort() End Sub Private Sub WebRequestProcedure() ' Create a request for the URL. Dim request As WebRequest = WebRequest.Create(webURL) ' If required by the server, set the credentials. request.Credentials = CredentialCache.DefaultCredentials 'Sets web request timeout time request.Timeout = 30000 ' 30000 = 30 Seconds ' Get the response. Dim response As HttpWebResponse = CType(request.GetResponse(), HttpWebResponse) 'Close the response request response.Close() End Sub Private Sub waitProcedure() Do 'Wait Five Mintues System.Threading.Thread.Sleep(300000) '300000 = 5 Minutes Try WebRequestProcedure() Catch ex As Exception Dim errorLog As New EventLog errorLog.WriteEntry("Virasec Heartbeat Service " & _ "has encountered an error while trying to " & _ "connect to the Virasec web server. " & _ "The service will attempt to " & _ "connect again in five minut

    P S D 3 Replies Last reply
    0
    • T tcombs07

      Hey guys the problem that I am is this. I am writting a service that every five minutes goes out and requests a web page. And the problem that I am having is whenever I disconnect my computer for the internet, the service throws an error. I have tried implementing some error handling but I can't seem to figure it out. I would like to code somethingso that if in 30 seconds a response is not gathered then to abort the request and try again in five minutes. Here is the code that i currently have: Imports System Imports System.IO Imports System.Net Imports System.Threading Public Class VirasecHB 'Declare the Thread Private VirasecHB_Thread As New Thread( _ New System.Threading.ThreadStart(AddressOf waitProcedure)) 'Declare Variables Dim serverID As String = "1336" Dim webURL As String = "http://www.virasec.com/intranet/tech/heart/heartdb.asp?hdur=300&hsid=" & serverID Protected Overrides Sub OnStart(ByVal args() As String) ' Add code here to start your service. This method should set things ' in motion so your service can do its work. WebRequestProcedure() VirasecHB_Thread.Start() End Sub Protected Overrides Sub OnStop() ' Add code here to perform any tear-down necessary to stop your service. VirasecHB_Thread.Abort() End Sub Private Sub WebRequestProcedure() ' Create a request for the URL. Dim request As WebRequest = WebRequest.Create(webURL) ' If required by the server, set the credentials. request.Credentials = CredentialCache.DefaultCredentials 'Sets web request timeout time request.Timeout = 30000 ' 30000 = 30 Seconds ' Get the response. Dim response As HttpWebResponse = CType(request.GetResponse(), HttpWebResponse) 'Close the response request response.Close() End Sub Private Sub waitProcedure() Do 'Wait Five Mintues System.Threading.Thread.Sleep(300000) '300000 = 5 Minutes Try WebRequestProcedure() Catch ex As Exception Dim errorLog As New EventLog errorLog.WriteEntry("Virasec Heartbeat Service " & _ "has encountered an error while trying to " & _ "connect to the Virasec web server. " & _ "The service will attempt to " & _ "connect again in five minut

      P Offline
      P Offline
      Paul Conrad
      wrote on last edited by
      #2

      tcombs07 wrote:

      the problem that I am having is whenever I disconnect my computer for the internet, the service throws an error.

      This line might be the problem...No internet connection, no getting to www.virasec.com.......

      tcombs07 wrote:

      Dim webURL As String = "http://www.virasec.com/intranet/tech/heart/heartdb.asp?hdur=300&hsid=" & serverID

      1 Reply Last reply
      0
      • T tcombs07

        Hey guys the problem that I am is this. I am writting a service that every five minutes goes out and requests a web page. And the problem that I am having is whenever I disconnect my computer for the internet, the service throws an error. I have tried implementing some error handling but I can't seem to figure it out. I would like to code somethingso that if in 30 seconds a response is not gathered then to abort the request and try again in five minutes. Here is the code that i currently have: Imports System Imports System.IO Imports System.Net Imports System.Threading Public Class VirasecHB 'Declare the Thread Private VirasecHB_Thread As New Thread( _ New System.Threading.ThreadStart(AddressOf waitProcedure)) 'Declare Variables Dim serverID As String = "1336" Dim webURL As String = "http://www.virasec.com/intranet/tech/heart/heartdb.asp?hdur=300&hsid=" & serverID Protected Overrides Sub OnStart(ByVal args() As String) ' Add code here to start your service. This method should set things ' in motion so your service can do its work. WebRequestProcedure() VirasecHB_Thread.Start() End Sub Protected Overrides Sub OnStop() ' Add code here to perform any tear-down necessary to stop your service. VirasecHB_Thread.Abort() End Sub Private Sub WebRequestProcedure() ' Create a request for the URL. Dim request As WebRequest = WebRequest.Create(webURL) ' If required by the server, set the credentials. request.Credentials = CredentialCache.DefaultCredentials 'Sets web request timeout time request.Timeout = 30000 ' 30000 = 30 Seconds ' Get the response. Dim response As HttpWebResponse = CType(request.GetResponse(), HttpWebResponse) 'Close the response request response.Close() End Sub Private Sub waitProcedure() Do 'Wait Five Mintues System.Threading.Thread.Sleep(300000) '300000 = 5 Minutes Try WebRequestProcedure() Catch ex As Exception Dim errorLog As New EventLog errorLog.WriteEntry("Virasec Heartbeat Service " & _ "has encountered an error while trying to " & _ "connect to the Virasec web server. " & _ "The service will attempt to " & _ "connect again in five minut

        S Offline
        S Offline
        SimulationofSai
        wrote on last edited by
        #3

        You have to mention the Error you're getting to get more precise answers. I can only make a wild guess with the information you've provided. Dim response As HttpWebResponse = CType(request.GetResponse(), HttpWebResponse) In most probability, the CType you're doing is throwing an error as the Reponse object returned by the GetResponse() method will be null if it can't reach the Http server. Enclose the above line in a Try..Catch block. AND, next time, post the error message or what it says, as well. SG

        1 Reply Last reply
        0
        • T tcombs07

          Hey guys the problem that I am is this. I am writting a service that every five minutes goes out and requests a web page. And the problem that I am having is whenever I disconnect my computer for the internet, the service throws an error. I have tried implementing some error handling but I can't seem to figure it out. I would like to code somethingso that if in 30 seconds a response is not gathered then to abort the request and try again in five minutes. Here is the code that i currently have: Imports System Imports System.IO Imports System.Net Imports System.Threading Public Class VirasecHB 'Declare the Thread Private VirasecHB_Thread As New Thread( _ New System.Threading.ThreadStart(AddressOf waitProcedure)) 'Declare Variables Dim serverID As String = "1336" Dim webURL As String = "http://www.virasec.com/intranet/tech/heart/heartdb.asp?hdur=300&hsid=" & serverID Protected Overrides Sub OnStart(ByVal args() As String) ' Add code here to start your service. This method should set things ' in motion so your service can do its work. WebRequestProcedure() VirasecHB_Thread.Start() End Sub Protected Overrides Sub OnStop() ' Add code here to perform any tear-down necessary to stop your service. VirasecHB_Thread.Abort() End Sub Private Sub WebRequestProcedure() ' Create a request for the URL. Dim request As WebRequest = WebRequest.Create(webURL) ' If required by the server, set the credentials. request.Credentials = CredentialCache.DefaultCredentials 'Sets web request timeout time request.Timeout = 30000 ' 30000 = 30 Seconds ' Get the response. Dim response As HttpWebResponse = CType(request.GetResponse(), HttpWebResponse) 'Close the response request response.Close() End Sub Private Sub waitProcedure() Do 'Wait Five Mintues System.Threading.Thread.Sleep(300000) '300000 = 5 Minutes Try WebRequestProcedure() Catch ex As Exception Dim errorLog As New EventLog errorLog.WriteEntry("Virasec Heartbeat Service " & _ "has encountered an error while trying to " & _ "connect to the Virasec web server. " & _ "The service will attempt to " & _ "connect again in five minut

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          You'd have to completely redesign this. All of your code was written on the assuption that the request would work and only the occasional error would happen. Turn it around and design the service so that it assumes that every request to the site will FAIL. For instance, this:

          Dim response As HttpWebResponse = CType(request.GetResponse(), HttpWebResponse)
          'Close the response request
          response.Close()

          always assumes that the response returns an object that you can close. Don't call close on an object that you don't know exists. Test for an object first, THEN call close on it if it's legitimate:

          Dim response As ...
          If response Is Nothing Then
          ' The request obviously failed...
          Else
          response.Close()
          End If

          A guide to posting questions on CodeProject[^]
          Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
               2006, 2007

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups