Hi,
I made a form, adding this code
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim oTimer(19) As MyTimer
For I As Integer = 0 To 19
oTimer(I) = New MyTimer
oTimer(I).Interval = 1000
oTimer(I).nID = I
AddHandler oTimer(I).Elapsed, AddressOf oTimer_Elapsed
oTimer(I).Start()
Next
End Sub
Public Sub oTimer_Elapsed(ByVal sender As Object, ByVal e As
System.Timers.ElapsedEventArgs)
Dim sArray() As String = System.IO.Directory.GetFiles("C:\T\" &
CType(sender, MyTimer).nID & "\", "*.*")
If Not sArray Is Nothing Then
If sArray.Length > 0 Then
Debug.WriteLine("Found file...")
End If
End If
End Sub
Public Class MyTimer
Inherits System.Timers.Timer
Private m_nID As Integer
Public Property nID() As Integer
Get
Return m_nID
End Get
Set(ByVal Value As Integer)
m_nID = Value
End Set
End Property
End Class
When running it (made 20 directories) it takes zero % processor power.
Also, a word of caution, a mistake that I made a while ago, if you create a
new timer and dont stop the old one (or run out of scope) it still elapes,
and when you have several thousand, the processor will start feeling it..
- Fredrik Melin
"LBT" <LB*@discussions.microsoft.com> wrote in message
news:E4**********************************@microsof t.com...
I have a window service written using VB.NET. This window service will scan
folders for file and grab the file content to be inserted to SQL Server on
file detection. There are altogether 18 folders to be watched. Each folder
is
assigned with a timer for watching purpose. Hence there will be 18 timers
and
each timer is set to elapse on every second.
Problem here, once the window service is installed and started, the CPU
usage is very high (take about 10% of overall CPU usage at a four 2GHz
processors server even when there is no file being sent in for
processing).
This highly comsumption of CPU power is because of the timers elapsed
event?
Any idea to improve it? Any advice and comment would be much appreciated.