Well...
I found out that in services there is no need to delegate when you work
with
timers (afaik..)
You did not provide this info in your previous post, i asumed you were bussy
with a threading mechanism as you only need control.InvokeRequired to
synchronize with the GUI thread , as a service does usually not provide a
GUI ( although not impossible with some help of remoting or named pipes etc
etc )
you are right .
By the way it is not such a good idea to use Timers in a windows service
Windows timers can`t be used at all , a timer that does work is the system
threading timer , however it is much easier and reliable to use a loop with
a thread sleep for x miliseconds
i myself have always written my windows services with a threading timer ,
until we had once a discussion here in this newsgroup ( June 2007 )
where one of the active and valued persons here brought up a good point
<<<<
IMHO, there's one very Good Reason for /not/ using a Timer.
It's called JIT compilation.
You write a Service and put a Timer in it.
You code up the routine that the Timer calls.
This routine references an external Assembly.
You deploy the Service.
Somehow, you miss the dependent assembly.
Your deployed service runs!
It starts and stops perfectly!
It doesn't report /any/ errors or Exceptions!
But it never does any useful work.
Why???
When the Timer fires, the runtime attempts to JIT the method invoked by
the Timer.
With the referenced Assembly /missing/, this JIT-linking fails but the
runtime doesn't report this and, if the Exception gets logged anywhere,
I've /never/ managed to find it. You can't catch this Exception - it's
gets thrown into the depths of the runtime and the Service
Infrastructure - you never see it.
I've found that calling the "worker" method from another one inside the
service - one /with/ a loop and Sleep(s) - works 100% reliably, and you
even get to catch the Exception if you really want to. ;-)
Regards,
Phill W.
>>>>
Thought this might be interesting info for you
HTH
Michel Posseth
"Guy Cohen" <Gu******@discussions.microsoft.comschreef in bericht
news:18**********************************@microsof t.com...
Hi
Well...
I found out that in services there is no need to delegate when you work
with
timers (afaik..)
So there is no problem :)
Guy Cohen
"Michel Posseth [MCP]" wrote:
>InvokeRequired is only used with GUI elements a code dll is obviously
not a
GUI element so there is your problem
if you want to update a GUI element with the timers event then you need
to
use InvokeRequired on that element in the called method of the GUI
class
hth
Michel
"Guy Cohen" <Gu******@discussions.microsoft.comschreef in bericht
news:8B**********************************@microso ft.com...
Hi all
I wrote a small demo program to understand timers and delegation - and
its
working fine.
However, I would like to use the timer in a DLL(Class)
When I compile the code:
Protected Sub Timer2_Elapsed(ByVal sender As Object, ByVal e As
ElapsedEventArgs)
If Me.InvokeRequired Then
Dim MyIncrement As New IncrementDelegate(AddressOf
MyTimerHander)
Me.BeginInvoke(MyIncrement)
End If
End Sub
I get the error InvokeRequired is not a part of <my class name goes
here>
Please advise
TIA
Guy Cohen