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

  • Home
  • SEARCH
  • 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 243613
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T20:56:09+00:00 2026-05-11T20:56:09+00:00

How do I pass along an event between classes? I know that sounds ridiculous

  • 0

How do I pass along an event between classes?

I know that sounds ridiculous (and it is) but I’ve been stumped on this for the past little while. Search didn’t turn up a similar question so I figured I would pose it.

Here are the objects involved:

WinForm -> Speaker -> Tweeter
                   -> Woofer

[Speaker, Tweeter, Woofer] all declare a “SpeakToMe” event that sends a simple string message. The events are declared using the standard pattern:

public delegate void SpeakToMeHandler(object sender, SpeakToMeEventArgs e);
public event SpeakToMeHandler SpeakToMe;
protected virtual void OnSpeakToMe(string message)
{
   if (SpeakToMe != null) SpeakToMe(this, new SpeakToMeEventArgs(DateTime.Now.ToString() + " - " + message));
}

SpeakToMeEventArgs is a simple class inheriting from EventArgs & containing a string property (Message).

On their own, each of these events works fine. E.g., I set a button in the form to create, subscribe, and fire the event for [Speaker, Tweeter, Woofer]. Each reports back properly.

The problem is when Speaker creates a [Tweeter, Woofer] and subscribes to their events.

What I want is for [Tweeter, Woofer] to fire their event, Speaker to consume it and fire it’s own event. I thought this should be very straight forward:

void tweeter_SpeakToMe(object sender, SpeakToMeEventArgs e)
{
   Console.Out.WriteLine("the tweeter is speaking: " + e.Message);
   this.OnSpeakToMe("tweeter rockin' out [" + e.Message + "]");
}

Stepping through this function (in Speaker), Console.Out.WriteLine works. Continuing to step through OnSpeakToMe, shows that the delegate is null.

Speaker’s SpeakToMe event is subscribed to by the form. I understood that this should prevent the event’s delegate from being null.

I’m sure this is an easy one, what am I missing?

Btw, in case you’re curious as to why I’m looking for this. [Speaker, Tweeter, Woofer] are my demo stand-ins for a really long data processing operation. The form runs several of these concurrently and requires progress updates from each class.

As always, any and all help is greatly appreciated!

Update: Thanks for all of the feedback everyone. I really appreciate the help! I picked up a couple of good tips (@David Basarab & @Brian) and a few different ideas on how to structure things. Again, much appreciated!

  • 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-05-11T20:56:10+00:00Added an answer on May 11, 2026 at 8:56 pm

    If I understood what you wanted in the basic sense. Is to have the Tweeter and Woofer fire an event that the Speaker is subscribed too then fire its own.

    Here is my code that has this output

    OUTPUT

    OnSpeak Message = OnSpeakToMeHander Orginal Message: Fired By Tweeter

    OnSpeak Message = OnSpeakToMeHander Orginal Message: Fired By Woofer

    class Program
    {
    
        static void Main(string[] args)
        {
            Console.Clear();
    
            try
            {
                Speaker speaker = new Speaker();
                speaker.speakerEvent += new SpeakToMeHandler(Program.OnSpeak);
    
                // Cause events to be fied
                speaker.Tweeter.CauseEvent();
                speaker.Woofer.CauseEvent();
    
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error: {0}", ex.Message);
                Console.WriteLine("Stacktrace: {0}", ex.StackTrace);
            }
        }
    
        public static void OnSpeak(object sendere, SpeakToMeEventArgs e)
        {
            Console.WriteLine("OnSpeak Message = {0}", e.Message);
        }
    
    }
    
    public delegate void SpeakToMeHandler(object sender, SpeakToMeEventArgs e);
    
    public class SpeakToMeEventArgs : EventArgs
    {
        public string Message { get; set; }
    }
    
    public class Speaker
    {
        public event SpeakToMeHandler speakerEvent;
    
        public Tweeter Tweeter { get; set; }
        public Woofer Woofer { get; set; }
    
        public void OnSpeakToMeHander(object sender, SpeakToMeEventArgs e)
        {
            if (this.speakerEvent != null)
            {
                SpeakToMeEventArgs args = new SpeakToMeEventArgs
                    {
                        Message = string.Format("OnSpeakToMeHander Orginal Message: {0}", e.Message)
                    };
    
                this.speakerEvent(this, args);
            }
        }
    
        public Speaker()
        {
            this.Tweeter = new Tweeter();
            this.Woofer = new Woofer();
    
            Tweeter.tweeterEvent += new SpeakToMeHandler(this.OnSpeakToMeHander);
            Woofer.wooferEvent += new SpeakToMeHandler(this.OnSpeakToMeHander);
        }
    }
    
    public class Tweeter
    {
        public event SpeakToMeHandler tweeterEvent;
    
        public void CauseEvent()
        {
            SpeakToMeEventArgs args = new SpeakToMeEventArgs()
                {
                    Message = "Fired By Tweeter"
                };
    
            if (this.tweeterEvent != null)
            {
                this.tweeterEvent(this, args);
            }
        }
    }
    
    public class Woofer
    {
        public event SpeakToMeHandler wooferEvent;
    
        public void CauseEvent()
        {
            SpeakToMeEventArgs args = new SpeakToMeEventArgs()
                {
                    Message = "Fired By Woofer"
                };
    
            if (this.wooferEvent != null)
            {
                this.wooferEvent(this, args);
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 276k
  • Answers 276k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer IIS will only pass a request to the ASP.NET process… May 13, 2026 at 2:48 pm
  • Editorial Team
    Editorial Team added an answer You must include any referenced assemblies as they are dependencies… May 13, 2026 at 2:48 pm
  • Editorial Team
    Editorial Team added an answer From my experience, py2exe handles imports in a weird way.… May 13, 2026 at 2:48 pm

Related Questions

I have created a Data Access Layer using .NET. Everywhere that I update a
I've been asked to display the 'correct' time on our website which I frankly
We're looking for someone to help us enhance & maintain our high-quality, php-based prototype
I have this situation where I want to display a list of Administration objects

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.