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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T13:27:38+00:00 2026-06-04T13:27:38+00:00

I’m having a bit of a problem with implementing an event architecture in C#.

  • 0

I’m having a bit of a problem with implementing an event architecture in C#. The basic layout is like this:

We have a network-layer(dll) that communicates with a server. This layer has made several interfaces for events of changes within the database. A database-field changes and the dll calls my implementation of the appropriate interface. I have a GUI, and within it’s main method a data-object, which stores lists of temporary data I display until something gets changed by my user, in which case I’ll send the changes to the database.

The problem is now that I can’t implement an event-handler within the network-layer, or my implementation of it’s interfaces, because my data-object(which should get the results of the events) only exists within my GUI, and it’s main method, and as such is not known to the appropriate objects.

I’ll make an example as pseudo-code:

namespace ClientConnection
{
    public class DataListener : IDataListener
    {
        public delegate void SomethingReceivedHandler(object sender, SomethingData packet);
        public event SomethingReceivedHandler somethingRecievedHandler;

        public void SomethingReceived(SomethingData packet)
        {
            if (SomethingRecievedHandler != null)
            {
                SomethingRecievedHandler(this, packet);
            }
        }

Is my current implementation of the interface. The Layer has something akin to:

 private void ProcessPacket(SomethingData packet)
        {
            if (packet == null)
                return;
            try
            {
                if (packet is SomethingData)
                    DataListener.SomethingReceived(packet as SomethingData);
//snip

And my main-method is:

public partial class Main : FormMain
    {
        Data ClientData; //Contains all temporary data within the GUI

        public frmMain()
        {
            ClientData = new Data();
            DataListener dataListener = newDataListener();
            InitializeComponent();
        }

And if the event fires I want to do something like:
ClientData.SomeList.Add(packet)
depending on the context.

  • 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-04T13:27:40+00:00Added an answer on June 4, 2026 at 1:27 pm

    The problem is now that I can’t implement an event-handler within the network-layer, or my implementation of it’s interfaces, because my data-object(which should get the results of the events) only exists within my GUI, and it’s main method, and as such is not known to the appropriate objects.

    Not sure I see the problem. The publisher of the event doesn’t need to know anything about the subscriber of the event – that’s what makes them useful.

    Based on your pseudo-code, it should be as simple as:

    public partial class Main : FormMain
    {
        Data ClientData; //Contains all temporary data within the GUI
    
        public frmMain()
        {
             ClientData = new Data();
             DataListener dataListener = new DataListener();
             // Add an event handler
             dataListener.somethingReceivedHandler += 
                 (object sender, SomethingData packet)              
                 {
                    if (someContext) ClientData.SomeList.Add(packet); 
                 };
             InitializeComponent();
        }
    

    You probably want to elevate dataListener to a field (instead of a local) so that it stays alive outside of the ctor (and you can unsubscribe when your form closes).

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have some data like this: 1 2 3 4 5 9 2 6
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have just tried to save a simple *.rtf file with some websites and
I would like to count the length of a string with PHP. The string

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.