473,218 Members | 1,497 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,218 software developers and data experts.

Efficient way to firing event.....

Hi All,

I am using the following method "FireAsync" (i got the following
information from the google groups) to fire the event for all the
subscribers.

Is there another way to fire the event to all the subscriber
asynchronously efficiently. As because in my application this method is
being call 60-100 times a second.

Any idea?
---------------------------------------------------------------------

delegate void AsyncInvokeDelegate(Delegate del, params object[] args);

public static void FireAsync(Delegate del, params object[] args)

{

if (del == null)

{

return;

}

Delegate[] delegates = del.GetInvocationList();
AsyncInvokeDelegate invoker = new
AsyncInvokeDelegate(InvokeDelegate);

foreach (Delegate sink in delegates)

{

invoker.BeginInvoke(sink,args,null,null);

}

}
private static void InvokeDelegate(Delegate sink, params object[] args)

{

try

{

sink.DynamicInvoke(args);

}

catch

{}

}

-------------------------------------------------------------------------------------
Thanks,
Utkarsh

Dec 21 '05 #1
6 1713
In C# the \ char needs to be repleced with \\ meaning:

XmlNodeList rss = doc.SelectNodes("//item");

needs to be:
XmlNodeList rss = doc.SelectNodes("////item");
or
XmlNodeList rss = doc.SelectNodes(@"//item");

Dec 21 '05 #2
Sorry I replied to the wrong post Should be linked to Whats the difference.
Dec 21 '05 #3
utkarsh,

How exactly are you defining efficient? Just because you fire your
events on multiple threads doesn't mean that you are going to make it more
efficient.

What is it you are trying to achieve? Depending on the number of
delegates that you have subscribed to your event, combined with the fact
that you are calling this 60-100 times a second, you could very well end up
filling up the thread pool to the point where you are adding delegate calls
faster than you can execute them.

If you want a speed increase, I would recommend defining an interface
and then passing interface implementations to your class for callbacks.
This will be faster than calling a delegate.

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

"utkarsh" <ut***********@gmail.com> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.com...
Hi All,

I am using the following method "FireAsync" (i got the following
information from the google groups) to fire the event for all the
subscribers.

Is there another way to fire the event to all the subscriber
asynchronously efficiently. As because in my application this method is
being call 60-100 times a second.

Any idea?
---------------------------------------------------------------------

delegate void AsyncInvokeDelegate(Delegate del, params object[] args);

public static void FireAsync(Delegate del, params object[] args)

{

if (del == null)

{

return;

}

Delegate[] delegates = del.GetInvocationList();
AsyncInvokeDelegate invoker = new
AsyncInvokeDelegate(InvokeDelegate);

foreach (Delegate sink in delegates)

{

invoker.BeginInvoke(sink,args,null,null);

}

}
private static void InvokeDelegate(Delegate sink, params object[] args)

{

try

{

sink.DynamicInvoke(args);

}

catch

{}

}

-------------------------------------------------------------------------------------
Thanks,
Utkarsh

Dec 22 '05 #4
Hi Nicholas,

Yes, I want to make it very efficient in terms of the CPU utilization.

My actual problem is as following:-
I am getting the data from the server. It is coming very fast 60-100
times a second.
I each event there are bunch of records are coming. These events are
received on a Static Class, where I fill my class object with data and
add it to collection and then fire an event using the FireAsync()
method as shown in my first post.

There are different 4-5 child form window which further receives these
events. Each window receives the event pickup the relevent data,
add/update/delete in the local arraylist variable. Sort the Data using
the quicksort and then call the refresh() to update the visible rows on
a panel. I am drawing the data myself in tabular form like a grid on a
panel in the OnPaint method.
Since it was very slow to use the datasource and DataGrid or
Infragisitics because updates are coming so faster and these take time
to sort and update on UI.

Now the problem event I have optimized the code at different level as
best i could do, it take more CPU cycle when all the 4-5 windows are
open and so fast processing is going on.

Even If I minimize the 5 window (so no need to paint by window) it
takes 50-80% CPU cycles becuase updates are coming very fast.

But now onwards I am not calling the Refresh() in the event handler of
child window form. I am running a timer in static class which is
notifiing all the 5 window to refresh in every 5 second, this is
helping me much better, but still CPU goes very high to 100% if updates
are more than 90-100 in a second.

So what do you think now in this scenario what are other scope of
improvement here?

Thanks,
Utkarsh

Dec 22 '05 #5
Actual goal of doing all this is to make the UI more responsive. It
freezes at high CPU usage.

Thanks,
Utkarsh

Dec 22 '05 #6
utkarsh wrote:
Actual goal of doing all this is to make the UI more responsive. It
freezes at high CPU usage.

Thanks,
Utkarsh


Without going into too much detail, in cases like this, you should try
to process the incoming data in batches instead of breaking it up into
little threadpool workunits. You can't increase the CPU power by using
multiple threads if you have just one core. And there is also the
overhead of GetInvocationList(), BeginInvoke() etc.

HTH,
Stefan

Dec 22 '05 #7

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

Similar topics

0
by: Ram | last post by:
I have a start page for my application default.htm which contains four frames. header.htm login.aspx rightside.htm footer.htm login.aspx conatins username, password fields and login button....
1
by: Diana | last post by:
I've got a database that has been working successfully for a number of years now. I just added a new item - basically a field that becomes visible depending on another field's value. When I was...
5
by: Joe | last post by:
Hi I am adding a class to a ComboBox - and all is fine except that I fill the combobox on the Form_Load Method and it causes the method private void comboBox2_SelectedIndexChanged(object...
4
by: Joergen Bech | last post by:
I sometimes use delegates for broadcasting "StateChanged" events, i.e. if I have multiple forms and/or controls that need updating at the same time as the result of a change in a global/common...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

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.