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 6120339
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:39:25+00:00 2026-05-23T15:39:25+00:00

I have three classes, one class loads in a configuration file into memory for

  • 0

I have three classes, one class loads in a configuration file into memory for access later on. My other class is the mainform. What I am attempting to achieve is that when certain elements of the configuration class are loaded in they are added to a listview in the GUI (WindowsForm).

I know you can’t access the GUI directly from the other non-mainform classes, which after reading I don’t want to do anyway, so I have been attempting to fire events to say “config updated” that the mainform will listen for and update the listview when appropriate. So I created a third class that defines the events and the delegates etc but in all the examples I’ve seen if different classes are calling the event they are all passed a shared instance of the event class.

Is this the way I should do things? When I created the configuration class from the mainform class should I pass an instance of the event class? Or is there a way for 2 classes that don’t know anything about each other to share an event?

I’ve modified a microsoft example below to semi demonstrate what I’m needing.

    using System;

public class FireEventArgs : EventArgs
{
    public FireEventArgs(string room, int ferocity)
    {
        this.room = room;
        this.ferocity = ferocity;
    }
    public string room;
    public int ferocity;
}

public class FireAlarm
{
    public delegate void FireEventHandler(object sender, FireEventArgs fe);
    public event FireEventHandler FireEvent;

    public void ActivateFireAlarm(string room, int ferocity)
    {
        FireEventArgs fireArgs = new FireEventArgs(room, ferocity);
        if(FireEvent!=null)FireEvent(this, fireArgs);
    }
}

public class FireEventTest
{

    public static void ExtinguishFire(object sender, FireEventArgs fe)
    {

        Console.WriteLine("\nThe ExtinguishFire function was called by {0}.", sender.ToString());
        if (fe.ferocity < 2)
            Console.WriteLine("This fire in the {0} is no problem.  I'm going to pour some water on it.", fe.room);
        else if (fe.ferocity < 5)
            Console.WriteLine("I'm using FireExtinguisher to put out the fire in the {0}.", fe.room);
        else
            Console.WriteLine("The fire in the {0} is out of control.  I'm calling the fire department!", fe.room);
    }

    public static void Main()
    {
        FireAlarm myFireAlarm = new FireAlarm();
        FireAlarm fireAlarm = new FireAlarm();
        fireAlarm.FireEvent += new FireAlarm.FireEventHandler(ExtinguishFire);
        myFireAlarm.ActivateFireAlarm("Kitchen", 3);
        myFireAlarm.ActivateFireAlarm("Study", 1);
        myFireAlarm.ActivateFireAlarm("Porch", 5);
        return;

    }   
}

Thanks in advance for any help.

  • 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-23T15:39:26+00:00Added an answer on May 23, 2026 at 3:39 pm

    Well, I don’t think that I understand you fully, but you can have a class called EventDispatcher, make it Singleton if you want, and inside it have a public event

    ConfigurationElementLoaded(object sender, ConfigurationElementLoadedArgs args)

    and a public method to fire the event:

    void FireConfigurationElementLoaded(ConfigurationElement element)
    

    in which you fire the event.

    Your mainForm can subscribe via the Singleton isntance : EventDispatcher.Instance.ConfigurationElementLoaded += ...

    and your Configuration can fire the event with FireConfigurationElementLoaded.

    If this answer doesn’t help, please elaborate more what exactly you want to do…

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

Sidebar

Related Questions

If I have minimum 2 classes. One class creates the Bitmap and the other
Say I have three classes: class X{}; class Y{}; class Both : public X,
Using threads, I have a principal class ( SlaveCrawler ) that instantiates three classes(
Suppose I have three classes. It is valid to instantiate A, but there are
If I have three classes, A, B, C. A and B are friends (bidirectionally).
I have three (C++) classes: Player, Hand, and Card. Player has a member, hand,
I have a three nested classes, Show, Season and Episode, where a show has
Let's say I have a Base class and several Derived classes. Is there any
I have a re-occurring design problem with certain classes which require one-off initialization with
In a WCF service, I have two classes with the [DataContract] attribute. One of

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.