473,503 Members | 1,677 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

re-use EventArgs or not

Hi
I use a event in a extensive calculation method to inform a client.

therefor i implement a eventhandler and eventargs (e.g. myEvent,
myEventArgs) and a OnMyEvent(myEventArgs e) method to fire the event.

e.g.

// extensive calculation in 2 dim.
for (int x = 0; x < xMax; x++)
{

for (int y = 0; y < yMax; y++)
{

float flow = calculateflow(....)

// here i will inform the client -- create always a new
myEventArgs

myEventArgs e = new myEventArgs( x,y, xMax, yMax, flow);
OnMyEvent(e);
....
alternatively i can do:

myEventArgs e = new myEventArgs(x,y);

for (int x = 0; x < xMax; x++)
{

for (int y = 0; y < yMax; y++)
{

float flow = calculateflow(....)

// here i will inform the client - using one and the same
"e"

e.X = x;
e.Y = y;
e.Flow = flow;

OnMyEvent(e);
....
"What is the better way"
particularly with regard to performance and resources ?

Is there a "DotNet recommendation" ?
thanks
Peter

Nov 17 '05 #1
1 1653
Generally speaking, the event args is only valid in the scope of the
event that it is being called in (at least, it should be treated that way,
logically). Also, if you don't have any properties on your event args that
require individual instances of the event args to be created (maybe there is
an object reference that is set in one of the event handlers?), then this
would be fine.

I mean, you know you are in a tight loop, and if you know that the
object will not be used beyond the initial calls to the event handlers, then
this is exactly what I would do.

If you want to get better performance, you might want to consider
passing an interface implementation to be called back. This would be faster
than calling the delegates.

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

<pR****@procom-gmbh.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
Hi
I use a event in a extensive calculation method to inform a client.

therefor i implement a eventhandler and eventargs (e.g. myEvent,
myEventArgs) and a OnMyEvent(myEventArgs e) method to fire the event.

e.g.

// extensive calculation in 2 dim.
for (int x = 0; x < xMax; x++)
{

for (int y = 0; y < yMax; y++)
{

float flow = calculateflow(....)

// here i will inform the client -- create always a new
myEventArgs

myEventArgs e = new myEventArgs( x,y, xMax, yMax, flow);
OnMyEvent(e);
...
alternatively i can do:

myEventArgs e = new myEventArgs(x,y);

for (int x = 0; x < xMax; x++)
{

for (int y = 0; y < yMax; y++)
{

float flow = calculateflow(....)

// here i will inform the client - using one and the same
"e"

e.X = x;
e.Y = y;
e.Flow = flow;

OnMyEvent(e);
...
"What is the better way"
particularly with regard to performance and resources ?

Is there a "DotNet recommendation" ?
thanks
Peter

Nov 17 '05 #2

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

Similar topics

4
6409
by: Craig Bailey | last post by:
Anyone recommend a good script editor for Mac OS X? Just finished a 4-day PHP class in front of a Windows machine, and liked the editor we used. Don't recall the name, but it gave line numbers as...
1
4079
by: Chris | last post by:
Sorry to post so much code all at once but I'm banging my head against the wall trying to get this to work! Does anyone have any idea where I'm going wrong? Thanks in advance and sorry again...
11
3987
by: James | last post by:
My form and results are on one page. If I use : if ($Company) { $query = "Select Company, Contact From tblworking Where ID = $Company Order By Company ASC"; }
10
4196
by: James | last post by:
What is the best method for creating a Web Page that uses both PHP and HTML ? <HTML> BLA BLA BLA BLA BLA
8
4396
by: Beowulf | last post by:
Hi Guru's, I have a query regarding using PHP to maintain a user profiles list. I want to be able to have a form where users can fill in their profile info (Name, hobbies etc) and attach an...
2
106586
by: sky2070 | last post by:
i have two file with jobapp.html calling jobapp_action.php <HTML> <!-- jobapp.html --> <BODY> <H1>Phop's Bicycles Job Application</H1> <P>Are you looking for an exciting career in the world of...
5
3614
by: Jamie Wright | last post by:
I have a problem with an HTML form. I have a form which I want to be able to type basic HTML code into it. When the submit button is selected the data is then previewed and added back into the text...
1
13616
by: Brian | last post by:
I have an array like this: $events = array( array( '2003-07-01', 'Event Title 1', '1' //ID Number (not unique) ), array( '2003-07-02',
2
5268
by: JW | last post by:
I wanted have this as part of a flood control script: <? echo ("Flood control in place - please wait " . $floodinterval . " seconds between postings."); sleep(5); // go back two pages echo...
2
3327
by: Frans Schmidt | last post by:
I want to make a new database with several tables, so I did the following: <?php CREATE DATABASE bedrijf; CREATE TABLE werknemers (voornaam varchar(15), achternaam varchar(20), leeftijd...
0
7202
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,...
0
7084
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...
0
7278
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,...
0
7328
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...
1
6991
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...
0
7458
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...
1
5013
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...
0
3167
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...
1
736
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.