473,387 Members | 1,485 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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 10 '05 #1
1 1196
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 10 '05 #2

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

Similar topics

4
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
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
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
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
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
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
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
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
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
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
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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
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
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...

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.