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 AsyncInvokeDele gate(Delegate del, params object[] args);
public static void FireAsync(Deleg ate del, params object[] args)
{
if (del == null)
{
return;
}
Delegate[] delegates = del.GetInvocati onList();
AsyncInvokeDele gate invoker = new
AsyncInvokeDele gate(InvokeDele gate);
foreach (Delegate sink in delegates)
{
invoker.BeginIn voke(sink,args, null,null);
}
}
private static void InvokeDelegate( Delegate sink, params object[] args)
{
try
{
sink.DynamicInv oke(args);
}
catch
{}
}
-------------------------------------------------------------------------------------
Thanks,
Utkarsh 6 1742
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");
Sorry I replied to the wrong post Should be linked to Whats the difference.
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.co m
"utkarsh" <ut***********@ gmail.com> wrote in message
news:11******** **************@ g47g2000cwa.goo glegroups.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 AsyncInvokeDele gate(Delegate del, params object[] args);
public static void FireAsync(Deleg ate del, params object[] args)
{
if (del == null)
{
return;
}
Delegate[] delegates = del.GetInvocati onList();
AsyncInvokeDele gate invoker = new AsyncInvokeDele gate(InvokeDele gate);
foreach (Delegate sink in delegates)
{
invoker.BeginIn voke(sink,args, null,null);
}
}
private static void InvokeDelegate( Delegate sink, params object[] args)
{
try
{
sink.DynamicInv oke(args);
}
catch
{}
}
-------------------------------------------------------------------------------------
Thanks, Utkarsh
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
Actual goal of doing all this is to make the UI more responsive. It
freezes at high CPU usage.
Thanks,
Utkarsh
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 GetInvocationLi st(), BeginInvoke() etc.
HTH,
Stefan This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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. When
the login is successful login page writes back javascript
|
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 testing this, I
noticed that the OnCurrent event wasn't firing. I went to an older
version of the program and saw that it wasn't firing there either. I
don't know how long this has been going on, but it's quite distressing.
To test the firing, I...
|
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 sender, EventArgs e)
To fire twice
Once when I comboBox2.DataSource = allMonths;
And again when I execute comboBox2.DisplayMember = "Name";
|
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 object,
I keep local references to this object in each UI
object, e.g.
Private WithEvents _tools As RepeatTools
and catch messages in an event handler like this:
|
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,...
| |
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...
|
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 captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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...
|
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 launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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...
|
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();...
| |
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |