I have built a windows service that should check whether a page can be returned from a site (from various servers). If not, it logs to the Application Error log. My trouble is this. It runs once, but doesn't seem to loop at all, ie, I only get the 1 round of warning messages (it also sends me a net message, but that will be removed eventually). My code for the whole service is below: - Imports System
-
Imports System.IO
-
Imports System.Net
-
Imports System.Text
-
Imports System.Net.Dns
-
Imports System.Threading
-
Imports System.ServiceProcess
-
-
Public Class IISPolling
-
Inherits System.ServiceProcess.ServiceBase
-
-
Private thrPollingThread As New Thread( _
-
New ThreadStart(AddressOf PollProcess))
-
-
Dim arrServers(2, 1) As String
-
Dim x, y As Integer
-
-
Const iChunk = 512
-
Dim arrRecipients() As String
-
Dim strLocalName As String = GetHostName()
-
Dim strServerName As String
-
Dim strMsg As String
-
Dim lngPos As Long = 1
-
-
#Region " Component Designer generated code "
-
-
Public Sub New()
-
MyBase.New()
-
-
' This call is required by the Component Designer.
-
InitializeComponent()
-
-
-
End Sub
-
-
'UserService overrides dispose to clean up the component list.
-
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
-
If disposing Then
-
If Not (components Is Nothing) Then
-
components.Dispose()
-
End If
-
End If
-
MyBase.Dispose(disposing)
-
End Sub
-
-
' The main entry point for the process
-
<MTAThread()> _
-
Shared Sub Main()
-
Dim ServicesToRun() As System.ServiceProcess.ServiceBase
-
-
ServicesToRun = New System.ServiceProcess.ServiceBase() {New IISPolling}
-
-
System.ServiceProcess.ServiceBase.Run(ServicesToRun)
-
End Sub
-
-
'Required by the Component Designer
-
Private components As System.ComponentModel.IContainer
-
-
' NOTE: The following procedure is required by the Component Designer
-
' It can be modified using the Component Designer.
-
' Do not modify it using the code editor.
-
Friend WithEvents logEvents As System.Diagnostics.EventLog
-
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
-
Me.logEvents = New System.Diagnostics.EventLog
-
CType(Me.logEvents, System.ComponentModel.ISupportInitialize).BeginInit()
-
'
-
'logEvents
-
'
-
Me.logEvents.EnableRaisingEvents = True
-
Me.logEvents.Log = "Application"
-
Me.logEvents.Source = "IISPolling"
-
'
-
'IISPolling
-
'
-
Me.ServiceName = "IISPolling"
-
CType(Me.logEvents, System.ComponentModel.ISupportInitialize).EndInit()
-
-
End Sub
-
-
#End Region
-
-
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.
-
logEvents.WriteEntry("IIS Polling service started on " & strLocalName & ".")
-
-
' Start the thread.
-
thrPollingThread.Start()
-
End Sub
-
-
Protected Overrides Sub OnStop()
-
' Add code here to perform any tear-down necessary to stop your service.
-
logEvents.WriteEntry("IIS Polling service stopped on " & strLocalName & ".")
-
-
' Stop the thread.
-
thrPollingThread.Abort()
-
End Sub
-
-
Private Sub PollProcess()
-
Do
-
' Wait...
-
Thread.Sleep(30000)
-
PollingPass()
-
Loop
-
End Sub
-
-
Private Sub PollingPass()
-
-
Dim request As HttpWebRequest
-
Dim response As HttpWebResponse
-
-
arrServers(0, 0) = "http://server1/DotNetNuke/Default.aspx"
-
arrServers(0, 1) = "serverA"
-
arrServers(1, 0) = "http://server2/DotNetNuke/Default.aspx"
-
arrServers(1, 1) = "serverB"
-
arrServers(2, 0) = "http://server3/DotNetNuke/Default.aspx"
-
arrServers(2, 1) = "serverC"
-
-
x = 0
-
Do Until x > arrServers.Length - 1
-
-
strServerName = arrServers(x, 1)
-
request = CType(WebRequest.Create(arrServers(x, 0)), HttpWebRequest)
-
-
'set some reasonable limits on resources used by this request
-
request.MaximumAutomaticRedirections = 4
-
request.MaximumResponseHeadersLength = 4
-
-
'set credentials to use for this request.
-
request.Credentials = CredentialCache.DefaultCredentials
-
-
Try
-
response = CType(request.GetResponse(), HttpWebResponse)
-
'TODO: take this line out otherwise the event log will just fill up
-
'logEvents.WriteEntry("IIS running on " & strServerName)
-
Catch ex As Exception
-
logEvents.WriteEntry("IIS on " & strServerName & " is not responding '" & _
-
ex.Message & "'", EventLogEntryType.Warning)
-
logEvents.WriteEntry("IIS service on " & strServerName & " - Stack Trace: " & _
-
ex.StackTrace, EventLogEntryType.Warning)
-
-
SendNetMsg("IIS Is Not Responding on server: " & strServerName) 'send a net message
-
-
End Try
-
x += 1
-
Loop
-
If Not response Is Nothing Then
-
response.Close()
-
End If
-
-
End Sub
-
-
Private Sub SendNetMsg(ByVal msg As String)
-
-
arrRecipients(0) = "myPC"
-
'arrRecipients(1) = "myPC2"
-
y = 0
-
-
Do Until lngPos > Len(strMsg)
-
Do Until y > arrRecipients.Length - 1
-
Dim lretval As Long = Shell("net send " & arrRecipients(y) & _
-
" """ & Mid(msg, lngPos, iChunk) & """", vbHide)
-
-
lngPos += iChunk
-
'pause to stop out of sequence message chunks
-
Thread.Sleep(100)
-
y += 1
-
Loop
-
Loop
-
-
End Sub
-
-
End Class
1 1325
My assumption is the exception is caught, sendnetmsg is called and runs only once as y=0 & arrRecipients.Length - 1=0. Therefore y only has to run once to be greater than 0.
Otherwise you will need to do some debugging - I would parse the code down until it is working and build it back up. HTH.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Fabio Papa |
last post by:
I am trying to write a windows service that sends emails to clients at
specific times based on information in a sql db. Since this is done for
multiple cities, I start a thread for each city and...
|
by: doug.h.taylor.accipitersoftware.com |
last post by:
Hi,
I need a general direction. I don't even know where to start
researching how to do this.
I have an existing dot net web application (It's mine, I wrote it)
that has some text fields and...
|
by: NWx |
last post by:
Hi,
I have an ASP.NET application which allow registered user to set-up
notifications, saved into an SQL server database.
I want to make a win service which periodically check this SQL server...
|
by: James Dixon |
last post by:
I have created a windows service in C#, .net framework 1.1
The service makes a web request using the
mshtml.HTMLDocument.CreateDocumentFromURL() function
Because this is not using...
|
by: linesh.gajera |
last post by:
Hi Guys,
I am creating a Windows service that call a routine at given interval.
Once routine is complete, windows service should wait for 5 minutes and
then call the routine again. I was using...
|
by: Dima Protchenko |
last post by:
Hi,
I am building a windows service, which monitors a mailbox and parses email messages into the db. When I wrote the SAME code in windows forms application, everything worked fine, but I am having...
|
by: Steven Thomas |
last post by:
I am writing an window service application in vb.net.
I have a sub that when called will start looping and doing work as
long as the service is running.
The problem I have is when I call the...
|
by: shil |
last post by:
Hi,
I am writing a windows app in .net 2003. I have a datagrid which gets
data from a storedprocedure. My question is how can I update the data
in the datagrid? I want to call another...
|
by: tshad |
last post by:
What would be a good way to check programmatically whether a service was
running?
We have a service that dies periodically and I need to check to see if this
service is running. I know how to...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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,...
|
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,...
|
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...
|
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...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
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,...
| |