Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8551999
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T14:19:24+00:00 2026-06-11T14:19:24+00:00

I setup a test console application using the below code: using System; class Program

  • 0

I setup a test console application using the below code:

using System;

class Program
{
    static void Main(string[] args)
    {
        var myEventGenerator = new EventGenerator();
        for (int i = 0; i < 10; i++)
            new EventListener(myEventGenerator);

        while (Console.ReadLine().Length == 0)
            myEventGenerator.TriggerEvent();
    }
}

class EventListener
{
    private static int numberOfInstances = 0;
    private int instanceNumber;

    public EventListener(EventGenerator eg)
    {
        eg.EventHappened += EventHappened;
        instanceNumber = numberOfInstances++;
    }

    void EventHappened(object sender, EventArgs e)
    {
        Console.WriteLine("Event Caught in Instance " + instanceNumber);
    }
}

class EventGenerator
{
    public event EventHandler EventHappened;

    public void TriggerEvent()
    {
        Console.WriteLine("Event Begin");
        if (EventHappened != null)
            EventHappened.Invoke(this, new EventArgs());
        Console.WriteLine("Event End");
    }
}

And the output of the application is:

Event Begin
Event Caught in Instance 0
Event Caught in Instance 1
Event Caught in Instance 2
Event Caught in Instance 3
Event Caught in Instance 4
Event Caught in Instance 5
Event Caught in Instance 6
Event Caught in Instance 7
Event Caught in Instance 8
Event Caught in Instance 9
Event End

Seems that the event listeners are triggering based on the order that they subscribed to the event.

But what if I don’t want those event listeners to occur in that order? What if I want it to be random? Or, if I want to specify a different order? Is there a way to do that?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T14:19:25+00:00Added an answer on June 11, 2026 at 2:19 pm

    There isn’t any way to change the order in which the event handler invokes the events hooked up to it. Check out this page for more info.

    Here is the important snippet:

    Invocation of a delegate instance whose invocation list contains
    multiple entries proceeds by invoking each of the methods in the
    invocation list, synchronously, in order. Each method so called is
    passed the same set of arguments as was given to the delegate
    instance. If such a delegate invocation includes reference parameters
    (Section 10.5.1.2), each method invocation will occur with a reference
    to the same variable; changes to that variable by one method in the
    invocation list will be visible to methods further down the invocation
    list. If the delegate invocation includes output parameters or a
    return value, their final value will come from the invocation of the
    last delegate in the list.

    If you want this kind of control, you’ll have to write some sort of class that does it for you.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

class Program { public delegate void VoidMethodDelegate(); public delegate int IntMethodDelegate(); static void Main(string[]
I am developing a PHP application using our XAMPP setup as a test server.
I have setup an android test project that runs junit tests. It's using two
I have setup a test database and console app to confirm the following: Given
I have setup a very simple test application to try RESTeasy on Jboss AS
yahoo YQL test console can list my contacts. whereas in my application i see
When you create a Setup project for a Windows/Console application, you find that there
I am using python's standard logging system to log my application. I want to
I want to setup my test/dev environment for Alfresco on Rackspace cloud, since I'm
I want to have a good test setup but, I can't find a way

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.