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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T10:45:27+00:00 2026-05-24T10:45:27+00:00

Im writing a simple client server app. On the client side I set up

  • 0

Im writing a simple client server app. On the client side I set up a singleton instance of class to do all communication with the server.
When new messages come in, I store them in a collection and then fire off an event. Any forms that are open and are subscribed to the event
will then receive the message and process it.

My problem is that if a form opens up after messages have been received, how do I send it the previously received messages and subscribe to
new ones without missing any messages, or getting one twice?

Form Code

private void Form_Load(object sender, EventArgs e)
{
        handleMsgRec = new EventHandler<MsgEventArgs>(MsgReceived);        

        Comm.Instance.LoadMsgs(Msgs);

        Comm.Instance.MsgReceived += handleMsgRec;
}

Server Communication Code

private static ReaderWriterLockSlim rw = new ReaderWriterLockSlim();

public void LoadMsgs(List<MsgObject> msgs)
{
        rw.EnterReadLock();
        Messages.ForEach(f => msgs.Add(f));
        rw.ExitReadLock();
}

edit: I dont think i explained myself well enough. I already am storing all of the messages that I receive. My concern is that between the time I load the messages and subscribe to the event, that a new message could come in that I would miss. Or if I subscribe to the event first and then load the messages, that I could wind up receiving a message twice.

  • 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-24T10:45:30+00:00Added an answer on May 24, 2026 at 10:45 am

    As Hans already mentioned: Store the previously received messages.

    Additionaly you could use a property for the MsgReceived event. In the “add” part of the property you could call the added delegate for any previous messages.

    public event EventHandler<MsgEventArgs> MsgReceived
    {
        add
        {
            foreach (MsgObject mo in msgs)
                value(this, new MsgEventArgs() { Message = mo });
    
            ...
        }
        remove
        {
            ...
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing a client/server app in C++ and need to realize simple protocol
I'm writing a simple console client-server app using MSMQ. I'm attempting to run it
I'm currently writing a simple cross platform app with Node.js on the server and
I am writing an auto update client. It's a very simple app that: 1)
I'm writing a simple client/server application and I found that using DataInputStream to read
I'm currently writing a simple client/server in Java using sockets. I want the server
I'm writing an sample app to create a Server on Android and a client
I'm writing a simple client/server application and am having trouble getting the client to
I'm writing my first client/server android app, and need an advice regarding server architecture.
I'm writing a simple app that's going to have a tiny form sitting in

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.