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 1340
My assumption is the exception is caught, sendnetmsg is called and runs only once as y=0 & arrRecipients.L ength - 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 continue the processing
from each thread. My service starts fine (gives me no errors, etc), but it
doesn't seem to start the new threads. I am new...
|
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 a button. The code-behind click event
of the button sends an SNPP conversation to a pager server.
I also have an existing dot net windows service...
|
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 table,
and send e-mail at the moment a notification is scheduled.
Question: what is the best way to implement this? Should I create a timer,
and in...
|
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 Windows.Forms, I can't use the
Application.DoEvents() function while the request is completing. Is there
an equivilent function (call the CreateDocumentFromURL...
|
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 System.Timers.Timer but i had
to remove it because of known bug(842739). Now i am using
System.Threading.Timer. It executes routine fine but the...
| |
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 a problem in the Windows Service project and I can't figure it out.
For i As Integer = objFolder.Items.Count To 1 Step -1
If TypeOf...
|
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 sub from the onstart sub the
service never thinks it has started. It remains in a "Starting"
state. Therefore I can not stop the service either.
...
|
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 storedprocedure to update the
data in the datagrid.
Thanks in advance.
|
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 check to see if the status is in stopped
or running mode. But that doesn't tell me if it is actually running.
I need to know this so that if it...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
| |
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| |