473,656 Members | 2,819 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Me.InvokeRequir ed

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
ElapsedEventArg s)

If Me.InvokeRequir ed Then
Dim MyIncrement As New IncrementDelega te(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
Jan 15 '08 #1
4 10759
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******@discu ssions.microsof t.comschreef in bericht
news:8B******** *************** ***********@mic rosoft.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
ElapsedEventArg s)

If Me.InvokeRequir ed Then
Dim MyIncrement As New IncrementDelega te(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

Jan 15 '08 #2
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******@discu ssions.microsof t.comschreef in bericht
news:8B******** *************** ***********@mic rosoft.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
ElapsedEventArg s)

If Me.InvokeRequir ed Then
Dim MyIncrement As New IncrementDelega te(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


Jan 15 '08 #3
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.InvokeR equired 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******@discu ssions.microsof t.comschreef in bericht
news:18******** *************** ***********@mic rosoft.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:
>InvokeRequir ed 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******@discu ssions.microsof t.comschreef in bericht
news:8B******* *************** ************@mi crosoft.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
ElapsedEventArg s)

If Me.InvokeRequir ed Then
Dim MyIncrement As New IncrementDelega te(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



Jan 15 '08 #4
Hi again

Well.. I did use an while/wend endless loop at first
But then it was difficult to stop the service.
Then I used 2 threads one for "service start command" and one for "service
stop command" (I wrote the service as a - small service that has two methods
stop and start and a dll that actually does everything and includes
stop/start methods - very easy to debug this way with a form that uses that
class/dll).
I added the timers as a watchdog (My guess is that you know what it is...)
It works 100% now :)

HTH
Guy Cohen

"Michel Posseth [MCP]" <MS**@posseth.c omwrote in message
news:uC******** ******@TK2MSFTN GP04.phx.gbl...
>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.InvokeR equired
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******@discu ssions.microsof t.comschreef in bericht
news:18******** *************** ***********@mic rosoft.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:
>>InvokeRequire d 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******@discu ssions.microsof t.comschreef in bericht
news:8B****** *************** *************@m icrosoft.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
ElapsedEventAr gs)

If Me.InvokeRequir ed Then
Dim MyIncrement As New IncrementDelega te(AddressOf
MyTimerHande r)
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


Jan 16 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
4842
by: Sgt. Sausage | last post by:
Problem. Work-around. No issues, just looking to see if I'm the only one that's seen this. I just lost 3 hours (shoulda found it sooner) to the InvokeRequired on a form being somewhat unreliable. It will sometimes return incorrect results. I've got it isolated to the Form's Handle property. If nothing touches my form's Handle before the supplementary threads are fired off, then InvokeRequired has about a
2
2180
by: BoloBaby | last post by:
Earlier, I had a threading issue where I had to use the InvokeRequired to get my controls to function properly. Does InvokeRequired apply to my custom classes as well? That is, if I have attempt to fire a method in a custom class as the result of an event raised by a user control, and the method doesn't seem to fire, is that because I have a threading problem again? What do I have to do in this case? Implement ISynchronizeInvoke on...
2
4071
by: Samuel R. Neff | last post by:
I'm trying to find a good way to handle Control.InvokeRequired without duplicating four lines of code in every function/event. Typically what I've seen in books is this: If InvokeRequired Then Invoke(new EventHandler(AddressOf thisFunc), new Object() { sender, e}) Return End If
5
9874
by: Michael C# | last post by:
Hi all, I set up a System.Timers.Time in my app. The code basically just updates the screen, but since the processing performed is so CPU-intensive, I wanted to make sure it gets updated regularly; like every 1.5 secs. or so. I only ran into one issue - the MyTimer_Elapsed event handler was not updating the screen correctly all the time, often leaving large chunks of the screen un-painted for several seconds. On a whim I decided to...
1
9490
by: Mesan | last post by:
I'm getting a "Cross-thread operation not valid" Exception and I can't figure out why. I've got a BackgroundWorker that creates a UserControl with a whole lot of other user controls inside of it, full of data I'm getting from the database. When my background worker completes I take e.Result and cast it back into a UserControl. I create a TabPage, add the returned UserControl to the Controls of the new TabPage and *BAM* there's my...
1
1714
by: Mark Denardo | last post by:
Hey all, I'm having a problem with the following: Private m_myDELEGATE As New myDELEGATE(AddressOf ReceivingServerMessage_UIThread) Delegate Sub myDELEGATE(ByVal ReceivingServerMessage As NetworkMessage) Public Sub ReceivingServerMessage(ByVal objNetworkMessage As NetworkMessage) If (Me.InvokeRequired) Then Dim args() As Object = {objNetworkMessage} Me.Invoke(m_myDELEGATE, args)
5
5624
by: RobKinney1 | last post by:
Wow... unbelieveable that this problem would arise right before giving the software to our public testers... or maybe it is believable. We tweaked some seemingly unrelated code somewhere else having nothing to to with this object, and now the following function is causing a System.StackOverflowException: private void ResetAllDataFieldsSafely() { if(myWebBrowser.InvokeRequired) //always evaluates to true
4
25474
by: Bill McCormick | last post by:
Hello, A timer control (I think) runs in another thread apart from a main form. In the OnTick event, you can update some form control with no worries. I'm making an AsyncronousServer class that runs in a separate thread and I'd like to have server generated events (OnListen, OnConnect, OnSend, OnRecieve, and so on) update a form control.
1
2121
by: Curious | last post by:
I have the following code: if (this.InvokeRequired) { IAsyncResult result = this.BeginInvoke(new EventHandler(this.UpdateButtons), new object { this, EventArgs.Empty }); while ((!result.IsCompleted) && (result.AsyncWaitHandle.WaitOne(100, false)))
0
8382
marktang
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8816
Oralloy
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8498
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8600
tracyyun
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6162
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4150
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4300
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2726
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
2
1930
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.