473,657 Members | 2,851 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(myEve ntArgs 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 1660
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.co m

<pR****@proco m-gmbh.com> wrote in message
news:11******** **************@ f14g2000cwb.goo glegroups.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(myEve ntArgs 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
6417
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 well as some color coding, etc. Having trouble finding the same in an editor that'll run on OS X. -- Floydian Slip(tm) - "Broadcasting from the dark side of the moon"
1
4090
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 for adding so much code... <TABLE border="1" bordercolor="#000000" cellspacing="0"> <TR>
11
3997
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
4212
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
4409
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 image, which will upload the record to a mySql db so users can then either view all profiles or query.. I.e. show all males in UK, all femails over 35 etc. Now, I'm not asking for How to do this but more what would be the best way? I've looked at...
2
106603
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 cyclery? Look no further! </P> <FORM NAME='frmJobApp' METHOD=post ACTION="jobapp_action.php"> Please enter your name:
5
3633
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 box again. Unfortunately all of the " charachters are escaped (I think that is the correct term) ie they have a leading \ added. This is causing me huge problems. I don't understand why that is happening. Any ideas? ...
1
13640
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
5295
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 "<script>window.history.go(-2);</script>"; exit; ?>
2
3335
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 tinyint(3), adres varchar(30), woonplaats varchar(20),
0
8303
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8821
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
8502
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
8602
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
5632
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
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...
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
1941
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.