Re: Efficient way to firing event.....
- From: "Nicholas Paldino [.NET/C# MVP]" <mvp@xxxxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Wed, 21 Dec 2005 18:59:44 -0500
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]
- mvp@xxxxxxxxxxxxxxxxxxxxxxxxxxx
"utkarsh" <utkarshpanwar@xxxxxxxxx> wrote in message
news:1135183377.166355.131920@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
> 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
>
.
- Follow-Ups:
- Re: Efficient way to firing event.....
- From: utkarsh
- Re: Efficient way to firing event.....
- References:
- Efficient way to firing event.....
- From: utkarsh
- Efficient way to firing event.....
- Prev by Date: Re: Formating money for display in a textbox
- Next by Date: [API] Win32 Resources - List Icon Resource Names
- Previous by thread: Re: Efficient way to firing event.....
- Next by thread: Re: Efficient way to firing event.....
- Index(es):
Relevant Pages
|