add method to the invocation list

  • Thread starter Thread starter Tony Johansson
  • Start date Start date
T

Tony Johansson

Hi!

I just wonder when adding method to the invcocation list of the EventHandler
is there possible to add as many methods as I like or is there some limited
size. I mean is the limitation only the amount of memory that you have.

//Tony
 
Tony Johansson said:
Hi!

I just wonder when adding method to the invcocation list of the
EventHandler is there possible to add as many methods as I like or is
there some limited size. I mean is the limitation only the amount of
memory that you have.
No fixed limit as far as I'm aware.

mick
 
Tony said:
Hi!

I just wonder when adding method to the invcocation list of the EventHandler
is there possible to add as many methods as I like or is there some limited
size. I mean is the limitation only the amount of memory that you have.

There is no predefined limit. If you have so many delegates in the
invocation list that you run out of memory, there's probably something
wrong. Either with your design or your implementation.

Pete
 
Where can I read that ?
Have you a URL where I can read about that?

If there are no limit specified in the docs, then you
can assume that it is just available resources that
limit it.

If you want to test then try:

using System;

namespace E
{
public class Program
{
private delegate void Demo(object sender, EventArgs args);
private static event Demo tst;
public static void Main(string[] args)
{
// let us test if it is actually working
for(int i = 0; i < 10; i++)
{
tst += Hello;
}
Console.WriteLine("if tst was called here we should see so
many hellos: " + tst.GetInvocationList().Length);
tst(null, null);
// let us try to add a lot
for(int i = 0; i < 1000000; i++)
{
tst += Hello;
}
Console.WriteLine("if tst was called here we should see so
many hellos: " + tst.GetInvocationList().Length);
// do not call tst here
Console.ReadKey();
}
public static void Hello(object sender, EventArgs args)
{
Console.WriteLine("Hello");
}
}
}

Arne
 
Back
Top