Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatically triggering an event?

Tags:

c#

events

How can I call this method programmatically? If I simple do KillZombies(), it says I don't have the correct parameters, but I don't know what parameters to specify when I'm just using code...

public static void KillZombies(object source, ElapsedEventArgs e)
{
    Zombies.Kill();
}
like image 558
sooprise Avatar asked Jul 22 '10 16:07

sooprise


People also ask

Can JavaScript trigger events?

This action can be accomplished through JavaScript event handlers. In addition to JavaScript, jQuery which is equivalent to JavaScript in terms of functionality can also be used to trigger events in a HTML document. In order to work on JavaScript trigger events, it is important to know what is an event.

How do I programmatically force an onchange event on an input?

Create an Event object and pass it to the dispatchEvent method of the element: var element = document. getElementById('just_an_example'); var event = new Event('change'); element. dispatchEvent(event);

What triggers an event?

What Is a Triggering Event? A triggering event is a tangible or intangible barrier or occurrence which, once breached or met, causes another event to occur. Triggering events include job loss, retirement, or death, and are typical for many types of contracts.


2 Answers

Have you tried:

KillZombies(null, null);

Perhaps refactor your design:

public static void KillZombies(object source, ElapsedEventArgs e)
{
    //more code specific to this event, logging, whathaveyou.
    KillSomeZombies();
}

public static void KillSomeZombies()
{
    Zombies.Kill();
}

//elsewhere in your class:
KillSomeZombies();
like image 113
p.campbell Avatar answered Sep 27 '22 18:09

p.campbell


KillZombies(null, null);

However, I would question whether that's a good design.

like image 37
Matthew Flaschen Avatar answered Sep 27 '22 18:09

Matthew Flaschen