473,836 Members | 1,935 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Raise Timer_Elapsed event

Hello,
is it possible to manually raise the event Elapsed of the timer object ?

Vittorio
Nov 20 '05
12 2948
Hi Herfried,

I find the fact not to do that for a timer more important than passing a
reference.

For the passing of parameters completely confirm the signature I see no
sense when it is not conform the sense of that signature although it are
objects.

So passing the same parameters when I have them is something I would always
do, however giving false parameters is in my eyes even more confusing, than
is nothing even better because that is testable to nothing.

To give you an example, you know that I like it to make a collection of
controls and than to add handlers to it, when I not send always the standard
object I would have to do in those events.

If typeoff sender Is Button then
if directcast(send er, button).name = etc.

This can as well as
If Not sender is Nothing then etc.

So there is not much benefit in my opinion when the sender is not the
expected object.

This is a long philosophic message this time.

Cor
"Herfried K. Wagner [MVP]" <hi************ ***@gmx.at> schreef in bericht
news:2k******** ****@uni-berlin.de...
* "Cor Ligthert" <no**********@p lanet.nl> scripsit:
This time I do *not* disagree with you, however it is possible.
This would mean that the first action would be to disable the timer.
However it was to show that you could do this with almost every event.

(Although for that handler method it would be probably the same, I think it is not right doing this for a timer and certainly not for another timer than the forms.timer, however just my thought).


You /can/ call an event handler the way you showed, but I would not pass
'Nothing' to the parameters. Instead I would pass a reference to the
control the event is belonging to in the 'sender' parameter and
'EventArgs.Empt y' in the 2nd parameter.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>

Nov 20 '05 #11
Vittorio,
In addition to the other comments:

Which Timer object (.NET has 3 timer objects)?

It appears that only the System.Timers.T imer object has an Elapsed event, as
Herfried stated, this Timer does not allow others to raise its events. The
normal patterns is to have an overridable protected OnElapsed method that
derived objects can call to raise the event.

In addition to considering the other suggestions, I would consider creating
a new class that encapsulates the Timer, this new class would have its own
Elapsed event, this new class would handle the Timer.Elapsed event, raising
its own Elapsed event, plus it would have a public method allowing other
objects to raise its Elapsed event. I would only really consider creating
this new class, if I wanted or needed to have multiple handlers of a single
Timer's Elapsed event, making calling the handler or a common procedure
"messy".

Hope this helps
Jay

"Vittorio Pavesi" <n@spam.net> wrote in message
news:%2******** ********@TK2MSF TNGP09.phx.gbl. ..
Hello,
is it possible to manually raise the event Elapsed of the timer object ?

Vittorio

Nov 20 '05 #12
* "Cor Ligthert" <no**********@p lanet.nl> scripsit:
I find the fact not to do that for a timer more important than passing a
reference.
The event has basically nothing to do with the timer. It's sort of
"callback" that is called when the event is raised. Passing empty data
can cause a 'NullReferenceE xception' if you access 'sender' and 'e'
inside the event handler. If you are the author of the code, that's not
a problem, but let's think about a team of programmers and one
programmer adds code to the event handler that accesses 'sender' and 'e'
inside the event handler and *BANG*, an exception is thrown.

There is a "pattern" in .NET's event handling, so that the developer can
expect 'sender' and 'e' to be supplied.
So passing the same parameters when I have them is something I would always
do, however giving false parameters is in my eyes even more confusing, than
is nothing even better because that is testable to nothing.
Why giving false parameters? By passing the reference to the timer in
the 1st parameter you are passing the correct value. By passing an
appropriate 'EventArgs' object (or an instance of one of its subclasses,
depending on the case) is not passing a wrong value too.
To give you an example, you know that I like it to make a collection of
controls and than to add handlers to it, when I not send always the standard
object I would have to do in those events.

If typeoff sender Is Button then
if directcast(send er, button).name = etc.

This can as well as
If Not sender is Nothing then etc.

So there is not much benefit in my opinion when the sender is not the
expected object.


Sure, that's why I would pass the expected object.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #13

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

Similar topics

1
10523
by: Dan Cimpoiesu | last post by:
I have a remoting object, derived from MarshalByRefComponent, that I instantiate on the client side, with Activator.GetObject. Can I receive events fired on the server, on the client? How?
2
1605
by: IcedCrow | last post by:
Subject says it all. I want to raise an event in Sub New of a class but it is not being raised to my client app. I can raise events just fine in other procedures... just not sub new. Why is this? Thanks in advance!
4
4541
by: Jeremy | last post by:
I have a combobox with a SelectionChangeCommitted event handler, and am having a problem raising this event. For example, raiseEvent mycombobox.SelectionChangeCommitted gives me an error about not being ended properly. But it won't accept parameters either. What's the trick here?
8
2452
by: NewUser | last post by:
Hello, I'm a new user to Visual Basic.net and I would appreciate any help regarding a problem I have. I have searched the posts in this newsgroup and the VB library for threading topics, but I get confused with the code that is displayed. Anyway, I have a System.Timers.Timer object in a form and its interval is 50 ms. I want to create a thread around the Timer_Elapsed event (ie. myThread = new System.Threading.Thread(AddressOf...
2
2082
by: Pietro | last post by:
Hello, somebody know how to raise an event from a nested class? I have two classes, the class1 with 1 events, and a nested class (class2) inside the class1. So... How can I raise class1 events from the class2? Public Class class1 Public Shared Event Evento1(ByRef sender As Object) Public Class class2
1
9944
by: Anonieko | last post by:
I know Visual Studio lacked support on easily writing code to raise events from a ascx user control ( because you have to hand write them). (http://codebetter.com/blogs/brendan.tompkins/archive/2004/10/06/27795.aspx) Question: Is it better and easier now in ASPNET 2.0 , meaning VS 2005?
3
2138
by: =?Utf-8?B?Ulc=?= | last post by:
I constructed a new Class with some private members. I would like an event to be raised on the moment the value of one of those private members is changed. How do I define an event for that private member and how do I raise the event? -- RW
5
2015
by: Mike | last post by:
Hi group; Let say I have an object called Account, that raises an event called AccountLow with its owns EventArgs, and when this event gets raised, I will like to raise another custom event called AccountGotLowAmount and passes AccountLow’s EventArgs along with the new event.
2
9154
by: Sin Jeong-hun | last post by:
Suppose class Engine do something in another thread and raise events. class Engine { Thread Worker; public event ... EngineMessage; public void Start() { Worker=new Thread(new ThreadStart(Run)); Worker.Start();
0
9810
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
10819
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...
0
10240
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...
0
9355
agi2029
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7772
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
6972
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5641
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...
2
4000
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3100
bsmnconsultancy
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.