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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T05:27:57+00:00 2026-06-13T05:27:57+00:00

I am using c# and events alot lately but I’m just starting to create

  • 0

I am using c# and events alot lately but I’m just starting to create my own events and use them. I’m a little confused on why to use the event keyword, I got the same result by only using delegates.

public partial class Form1 : Form
{
    ServerConnection connection = new ServerConnection();

    public Form1()
    {
        InitializeComponent();
        connection.ref = new del(MethOne);
        connection.ref += new del(MethTwo);
    }

    public void MethOne(object message)
    {
        MessageBox.Show((string)message);
    }

    public void MethTwo(object message)
    {
        MessageBox.Show((string)message);
    }

}


public delegate void del(string message);



public class ServerConnection
{
    private TcpListener tcpListener;
    public del ref;
    
    private List<NetworkStream> clientList = new List<NetworkStream>();

    public ServerConnection()
    {
        this.tcpListener = new TcpListener(IPAddress.Any, 3000);
        ThreadStart startListening = new ThreadStart(ListenForClients);
        Thread startThread = new Thread(startListening);
        startThread.Start();
    }


    public void ListenForClients()
    {
        tcpListener.Start();
        ParameterizedThreadStart handleClient = new ParameterizedThreadStart(HandleClient);

        while (true)
        {
            TcpClient newClient = tcpListener.AcceptTcpClient();
            Thread handleClientThread = new Thread(handleClient);
            handleClientThread.Start(newClient);
        }
    }


    public void HandleClient(object newClient)
    {
        NetworkStream clientStream = ((TcpClient)newClient).GetStream();
        clientList.Add(clientStream);

        BinaryFormatter formatter = new BinaryFormatter();
        string message;

        while (true)
        {
            message = (string)formatter.Deserialize(clientStream);
            ref((string)message);
        }
    }
  • 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-13T05:27:58+00:00Added an answer on June 13, 2026 at 5:27 am

    The event keyword lets you specify add and remove operations inline with the declaration.

    private Action _myEvent;
    
    public event Action MyEvent
    {
        add
        {
            Console.WriteLine("Listener added!");
            _myEvent += value;
        }
        remove
        {
            Console.WriteLine("Listener removed!");
            _myEvent -= value;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was using Events in my class and added an event reference to the
I have around 10 textboxes using the same events - I then just cast
I'm using events as part of a game model, and for extensibility and code
When using jQuery events such as click, mouseover and so, are there big differences
When delegating events using .on how do I target child elements: I have tried:
I am used to using inline events in my websites for example <head> <script>
I'm trying to intercept events using Gdk.Window.AddFilter(Gdk.FilterFunc) in Mono. So far, I have been
I'm having trouble understanding using D3 events and dispatch functions. I have a chart
How to detect click (including browser's back button) events using javascript?
The jQuery docs at http://api.jquery.com/on/ mention the benefits of delegated-events using the following syntax

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.