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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T03:53:18+00:00 2026-05-30T03:53:18+00:00

I want to send a message from a server to all clients. There are

  • 0

I want to send a message from a server to all clients. There are 0-* clients. The server may or may not be running when a client is loaded. The functionality here works how I want it. I am trying to figure out if this can be done without Thread.Sleep()? Also note that the clients and the server are each in independant processes.

Server Portion

class NamedEventsServer
{
    internal static void Main()
    {
        const string ewhName = "StickyNoteEwh";

        EventWaitHandle ewh = null;
        bool doesNotExist = false;
        bool wasCreated;

        // Attempt to open the named event.
        try
        {
            ewh = EventWaitHandle.OpenExisting(ewhName);
        }
        catch (WaitHandleCannotBeOpenedException)
        {
            Console.WriteLine("Named event does not exist.");
            doesNotExist = true;
        }
        if (doesNotExist)
        {
            // The event does not exist, so create it.

            ewh = new EventWaitHandle(true,
                EventResetMode.ManualReset,
                ewhName,
                out wasCreated);

            if (wasCreated)
            {
                Console.WriteLine("Created the named event.");
            }
            else
            {
                Console.WriteLine("Unable to create the event.");
                return;
            }
        }
        ewh.Set();
        Thread.Sleep(1000);//wait one second...giving threads enough time to all respond.  Then stop triggering the event.
        ewh.Reset();

        //exit
    }
}

Client Portion

class NamedEventsClient
{
    internal static void Main()
    {
        const string ewhName = "StickyNoteEwh";

        while (true)
        {
            EventWaitHandle ewh = null;
            bool doesNotExist = false;
            bool wasCreated;
            // Attempt to open the named event.
            try
            {
                ewh = EventWaitHandle.OpenExisting(ewhName);
            }
            catch (WaitHandleCannotBeOpenedException)
            {
                Console.WriteLine("Named event does not exist.");
                doesNotExist = true;
            }
            if (doesNotExist)
            {
                // The event does not exist, so create it.

                ewh = new EventWaitHandle(false,
                    EventResetMode.ManualReset,
                    ewhName,
                    out wasCreated);

                if (wasCreated)
                {
                    Console.WriteLine("Created the named event.");
                }
                else
                {
                    Console.WriteLine("Unable to create the event.");
                    return;
                }
            }
            Console.WriteLine("Wait on the event.");
            ewh.WaitOne();
            Console.WriteLine("Event was signaled.");
            //Console.WriteLine("Press the Enter key exit.");
            Thread.Sleep(1000);
            //Console.ReadLine();
        }
    }
}
  • 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-30T03:53:19+00:00Added an answer on May 30, 2026 at 3:53 am

    I guess it depends whether you’re certain all clients are going to get their time-slice within on second. It sounds reasonable, but under extreme stress some clients might miss it. How crucial is that?

    Anyway, I think this is exactly the kind of thing you should use ZeroMQ for. It’s light-weight, and takes care of all the potential bugs for you.

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

Sidebar

Related Questions

Let's say I want to send a message from one client to another. How
I want to send an SMS message from my facebook application so that the
How to trap signal on ruby running on windows? I want to send signal/message
We're using GWT Atmosphere to send strings from the server to the client and
I want to send message/notification to friends with customized subject with a link in
I want to send a message to a thread and handle it in the
I want to send a message whenever RabbitMQ creates or deletes a queue, exchange
I want to send an Email message after a page is returned to the
I want to send messages to mobile phones using wamp server in php.I need
Just to be clear, all of the TCPClients I'm referring to here are not

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.