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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T06:04:51+00:00 2026-06-15T06:04:51+00:00

In the context of a C# console application, if I make a loop used

  • 0

In the context of a C# console application, if I make a loop used to receive message asynchronously which raises an event for each message received, such as :

while (true)
{
   var message = await ReceiveMessageAsync();
   ReceivedMessage(new ReceivedMessageEventArgs(message));
}

Now if I have multiple subscribers to the event (let’s say 3 subscribers for the sake of the example), all of them using an asynchronous event handler such as :

async void OnReceivedMessageAsync(object sender, ReceivedMessageEventArgs args)
{
   await TreatMessageAsync(args.Message);
}

Should message object be coded in a thread safe way ? I think so, as TreatMessageAsync code from the different event handlers may run concurently for all the subscribers (when event is raised, the three async event handlers of the subscribers are called, each launching an async operation which potentially could be run concurently on different threads by the task scheduler). Or am I wrong ?

Thanks !

  • 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-15T06:04:52+00:00Added an answer on June 15, 2026 at 6:04 am

    You should code it in a thread-safe way. The easiest way to do so is to make it immutable.

    If you have a true event, then its arguments should be immutable. If you’re using an event handler for something that’s not a true event (like a command or implementation) then you may want to modify your API.

    It is possible to have concurrent event handlers because each handler will start sequentially, but they can resume concurrently.

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

Sidebar

Related Questions

In my c# console application , which takes string as arguments, I have a
Context: the application I'm trying to make does not display a form initially, but
What's the difference between console.log(process.cwd()) and console.log(__dirname); I've seen both used in similar contexts.
Context Clojure Agents are NOT sent new values. They are sent a function which
I'm trying to make a basic client-server application for windows phone 7 (using Mango
I use the following, static class to access the data context in my application
I have included the following statement in my Visual C# Console Application (Visual Studio
I just can't make out if the entity context is disposed in the usage
im am trying to make for a school project a client-server application in C#
I am currently working on an iPhone magazine application which downloads its magazine content

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.