I have the below code. What happens if the Upload method takes more than one minute for completion? Does the timer kick off another call to the Upload method immediately after one minute is over or Does it wait until the method finishes executing? I am implementing this as a windows service.
Protected Overrides Sub OnStart(ByVal args() As String)
Dim tmr As Timer = New Timer(New TimerCallback(AddressOf Upload), Nothing, 1000, **60000**)
While Not tmr Is Nothing
End While
End Sub
Public Sub Upload(ByVal o As Object)
Dim sr As StreamReader
..........
..........
End Sub
Though some of your code is confusing (what’s with the
Whileloop?), I can say yes, theTimerwill kick off anotherThreadfrom theThreadPool.You can use
Monitor,ReaderWriterLockSlim, orlockto control re-entrancy. You’ll need an object to lock onto and other things tie into your requirements (i.e. the integer specified tellsMonitorto try for X milliseconds, where 0 means we want the lock immediately):VB.NET:
C#:
EDIT: Oops, this is VB.NET! Let me convert my code…