add method to the invocation list

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
 
M

mick

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
 
P

Peter Duniho

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
 
A

Arne Vajhøj

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top