473,569 Members | 2,844 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

I always define events with two parameters

I always define events with the parameters

ByVal sender As Object, ByVal e As EventArgs

Even if they are not used.

Seems I read someplace that's the thing to do.

So I then do:

RaiseEvent AbortAll(Nothin g, Nothing)

Does that make sense to you?

Is that the standard practice?

Thanks
Nov 21 '05 #1
18 1433
>RaiseEvent AbortAll(Nothin g, Nothing)

Does that make sense to you?


Most event consumers will not expect either of the arguments to be
Nothing. I'd do

RaiseEvent AbortAll(Me, EventArgs.Empty )

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 21 '05 #2
Hi,

You will be punished by Herfried,

(I do it that way again as you write)

And before I will be punished as well (what I probably will despite that).

It gives you the posibility to use inside the event

If sender Is Nothing 'Then it is from inside the program.

(what is the same as in Mattias sample,
If sender Is me. What I have used in past).

:-)

Cor
Nov 21 '05 #3
> So I then do:
RaiseEvent AbortAll(Nothin g, Nothing)
Does that make sense to you?
No.
Is that the standard practice?


There is an unenforced convention that says you should make a class that
inherits eventargs, you put your event info in your properties in this new
class, and when you raise the event, you supply a sender (a form, a control,
an object of yours) and an instance of your class. It is described in the
..net help. A general benefit of this approach is that a property can be
added to the class without breaking the syntax of raising and handling the
event - if a new piece of event info is added, you would have to change all
event handlers. The consequences of that re the form load event, for
instance, are too awful to contemplate.

An alternative view is that events are just like methods and the calling
sequence can be whatever the class designer wants it to be. The idea is that
public methods provide a public face to the object for functionality, and
public events provide a public face to the object for
outloading/progress/notification/whatever. I prefer this approach in my own
apps, but I prefer convention in any circumstance where the class raising the
event could be widely deployed.

Nov 21 '05 #4
"Cor Ligthert [MVP]" <no************ @planet.nl> schrieb:
You will be punished by Herfried,


That's indeed true.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
Nov 21 '05 #5
**Developer**
In addition to the other comments:

I normally define my events as:

Public Event SomeNotificatio n As EventHandler

As EventHandler is a Delegate that is defined with the sender & e
parameters. Indirectly this minimizes the number of Delegates that are
defined. If you define your event as:

Public Class Something
Public Event SomeNotificatio n (ByVal sender As Object, ByVal e As
EventArgs)
End Class

Then VB creates a hidden Delegate for you, which you see in ILDASM.EXE as
Something.SomeN otificationEven tHandler.

If you have a lot of events like SomeNotificatio n, then you wind up with a
lot of Delegate types that are defined identically, leading to Assembly
bloat...
I normally call an OnSomeNotificat ion sub to raise the event.

OnSomeNotificat ion(EventArgs.E mpty)

When I raise the event, where OnSomeNotificat ion is defined as:

Protected Overridable Sub OnSomeNotificat ion(ByVal e As EventArgs)
RaiseEvent AbortAll(Me, e)
End Sub

Using OnSomeNotificat ion allows derived classes to both raise the event & to
add code before and/or after the event is raised. Normally I simply override
OnSomeNotificat ion to allow a derived class to simply handle the event,
rather then using AddHandler...
The above event pattern is defined at:

http://msdn.microsoft.com/library/de...guidelines.asp
and
http://msdn.microsoft.com/library/de...Guidelines.asp
--
Hope this helps
Jay [MVP - Outlook]
T.S. Bradley - http://www.tsbradley.net
" **Developer**" <RE************ *@a-znet.com> wrote in message
news:e%******** ********@TK2MSF TNGP12.phx.gbl. ..
|I always define events with the parameters
|
| ByVal sender As Object, ByVal e As EventArgs
|
| Even if they are not used.
|
| Seems I read someplace that's the thing to do.
|
| So I then do:
|
| RaiseEvent AbortAll(Nothin g, Nothing)
|
| Does that make sense to you?
|
| Is that the standard practice?
|
|
|
|
|
| Thanks
|
|
Nov 21 '05 #6
thanks

"AMercer" <AM*****@discus sions.microsoft .com> wrote in message
news:B5******** *************** ***********@mic rosoft.com...
So I then do:
RaiseEvent AbortAll(Nothin g, Nothing)
Does that make sense to you?


No.
Is that the standard practice?


There is an unenforced convention that says you should make a class that
inherits eventargs, you put your event info in your properties in this new
class, and when you raise the event, you supply a sender (a form, a
control,
an object of yours) and an instance of your class. It is described in the
.net help. A general benefit of this approach is that a property can be
added to the class without breaking the syntax of raising and handling the
event - if a new piece of event info is added, you would have to change
all
event handlers. The consequences of that re the form load event, for
instance, are too awful to contemplate.

An alternative view is that events are just like methods and the calling
sequence can be whatever the class designer wants it to be. The idea is
that
public methods provide a public face to the object for functionality, and
public events provide a public face to the object for
outloading/progress/notification/whatever. I prefer this approach in my
own
apps, but I prefer convention in any circumstance where the class raising
the
event could be widely deployed.

Nov 21 '05 #7
Great

Thanks
"Jay B. Harlow [MVP - Outlook]" <Ja************ @tsbradley.net> wrote in
message news:ex******** ******@TK2MSFTN GP12.phx.gbl...
**Developer**
In addition to the other comments:

I normally define my events as:

Public Event SomeNotificatio n As EventHandler

As EventHandler is a Delegate that is defined with the sender & e
parameters. Indirectly this minimizes the number of Delegates that are
defined. If you define your event as:

Public Class Something
Public Event SomeNotificatio n (ByVal sender As Object, ByVal e As
EventArgs)
End Class

Then VB creates a hidden Delegate for you, which you see in ILDASM.EXE as
Something.SomeN otificationEven tHandler.

If you have a lot of events like SomeNotificatio n, then you wind up with a
lot of Delegate types that are defined identically, leading to Assembly
bloat...
I normally call an OnSomeNotificat ion sub to raise the event.

OnSomeNotificat ion(EventArgs.E mpty)

When I raise the event, where OnSomeNotificat ion is defined as:

Protected Overridable Sub OnSomeNotificat ion(ByVal e As EventArgs)
RaiseEvent AbortAll(Me, e)
End Sub

Using OnSomeNotificat ion allows derived classes to both raise the event &
to
add code before and/or after the event is raised. Normally I simply
override
OnSomeNotificat ion to allow a derived class to simply handle the event,
rather then using AddHandler...
The above event pattern is defined at:

http://msdn.microsoft.com/library/de...guidelines.asp
and
http://msdn.microsoft.com/library/de...Guidelines.asp
--
Hope this helps
Jay [MVP - Outlook]
T.S. Bradley - http://www.tsbradley.net
" **Developer**" <RE************ *@a-znet.com> wrote in message
news:e%******** ********@TK2MSF TNGP12.phx.gbl. ..
|I always define events with the parameters
|
| ByVal sender As Object, ByVal e As EventArgs
|
| Even if they are not used.
|
| Seems I read someplace that's the thing to do.
|
| So I then do:
|
| RaiseEvent AbortAll(Nothin g, Nothing)
|
| Does that make sense to you?
|
| Is that the standard practice?
|
|
|
|
|
| Thanks
|
|

Nov 21 '05 #8
Doh!!

That should be:
| Protected Overridable Sub OnSomeNotificat ion(ByVal e As EventArgs)
| RaiseEvent SomeNotificatio n(Me, e)
| End Sub

Obviously the OnSomeNotificat ion raises the SomeNotificatio n event & not the
AbortAll event as I showed. ;-)

--
Hope this helps
Jay [MVP - Outlook]
T.S. Bradley - http://www.tsbradley.net
"Jay B. Harlow [MVP - Outlook]" <Ja************ @tsbradley.net> wrote in
message news:ex******** ******@TK2MSFTN GP12.phx.gbl...
| **Developer**
| In addition to the other comments:
|
| I normally define my events as:
|
| Public Event SomeNotificatio n As EventHandler
|
| As EventHandler is a Delegate that is defined with the sender & e
| parameters. Indirectly this minimizes the number of Delegates that are
| defined. If you define your event as:
|
| Public Class Something
| Public Event SomeNotificatio n (ByVal sender As Object, ByVal e As
| EventArgs)
| End Class
|
| Then VB creates a hidden Delegate for you, which you see in ILDASM.EXE as
| Something.SomeN otificationEven tHandler.
|
| If you have a lot of events like SomeNotificatio n, then you wind up with a
| lot of Delegate types that are defined identically, leading to Assembly
| bloat...
|
|
| I normally call an OnSomeNotificat ion sub to raise the event.
|
| OnSomeNotificat ion(EventArgs.E mpty)
|
| When I raise the event, where OnSomeNotificat ion is defined as:
|
| Protected Overridable Sub OnSomeNotificat ion(ByVal e As EventArgs)
| RaiseEvent AbortAll(Me, e)
| End Sub
|
| Using OnSomeNotificat ion allows derived classes to both raise the event &
to
| add code before and/or after the event is raised. Normally I simply
override
| OnSomeNotificat ion to allow a derived class to simply handle the event,
| rather then using AddHandler...
|
|
| The above event pattern is defined at:
|
|
http://msdn.microsoft.com/library/de...guidelines.asp
| and
|
http://msdn.microsoft.com/library/de...Guidelines.asp
|
|
| --
| Hope this helps
| Jay [MVP - Outlook]
| T.S. Bradley - http://www.tsbradley.net
|
|
| " **Developer**" <RE************ *@a-znet.com> wrote in message
| news:e%******** ********@TK2MSF TNGP12.phx.gbl. ..
||I always define events with the parameters
||
|| ByVal sender As Object, ByVal e As EventArgs
||
|| Even if they are not used.
||
|| Seems I read someplace that's the thing to do.
||
|| So I then do:
||
|| RaiseEvent AbortAll(Nothin g, Nothing)
||
|| Does that make sense to you?
||
|| Is that the standard practice?
||
||
||
||
||
|| Thanks
||
||
|
|
Nov 21 '05 #9
I've been reading the Help Doc and am confused about the Empty field.
Which is type EventArgs.
What is that all about?


It's like a dummy EventArgs instance you can supply when you don't
have anything else to add. By reusing the same instance you can save a
lot of small object allocations.
Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 21 '05 #10

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

Similar topics

83
15540
by: rahul8143 | last post by:
hello, what is difference between sizeof("abcd") and strlen("abcd")? why both functions gives different output when applied to same string "abcd". I tried following example for that. #include <stdio.h> #include <string.h> void main() { char *str1="abcd";
4
1276
by: news.microsoft.com | last post by:
In one of my books called "Mastering C#" there is a statement that reads "All event handler delegates must return void and accept two parameters. The first parameter is an object, and it represents the object that raises the event... The second is a parameter that is an object of a class derived from the System.EventArgs class". Now I know...
1
2832
by: Natalia DeBow | last post by:
Hi, I am working on a Windows-based client-server application. I am involved in the development of the remote client modules. I am using asynchronous delegates to obtain information from remote server and display this info on the UI. From doing some research, I know that the way my implementation works today is not thread-safe, because...
3
1583
by: Michael Tissington | last post by:
I'm confused by documentation and examples on using Delegate to create Events for use with COM In some situation I see a parameter list of (sender as Object, e as EventArgs) and other times I see no parameters, or a list of parameters that are event dependent. Below is my .NET code to create a class which raises some events. From C++...
19
5150
by: youpak2000 | last post by:
Are MAGIC numbers always bad? Using magic numbers (constant numbers) in programs are generally considered a bad programming practice, and it's recommended that to define constants in single, visible place in a header file. My question is that is there any situation where using magic numbers is not necessarily a bad thing? lets say that we...
16
2883
by: anonymous.user0 | last post by:
The way I understand it, if I have an object Listener that has registered as a listener for some event Event that's produced by an object Emitter, as long as Emitter is still allocated Listener will stay alive. Is this correct? If this is correct, I've got a problem. Let's say I've got an object Customer that has an PurchaseList...
11
3235
by: MikeT | last post by:
This may sound very elementary, but can you trap when your object is set to null within the object? I have created a class that registers an event from an object passed in the constructor. When my object is destroyed, I want my object to un-register this event. If I don't then the object would never be destroyed until the object I passed...
7
3409
by: Siegfried Heintze | last post by:
I'm studying the book "Microsoft Visual Basic.NET Language Reference" and I would like some clarify the difference between events and delegates. On page 156 I see a WinForms example of timer that uses the "WithEvents" and events. There is another example on page 124 that shows how to use delegates to sort an array. I don't understand the...
1
1073
by: shapper | last post by:
Hello, I am using a ListView connected with an ObjectDataSource. I am creating everything at runtime by implementing the ListView ITemplate. I know I get a one way bind so I need to define my parameters values by accessing the controls inside the template. Where should I define the paramater values, for example when inserting a new...
0
7612
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7922
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. ...
0
8119
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7668
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...
0
6281
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...
1
5509
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...
0
3653
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...
1
2111
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
0
936
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...

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.