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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T11:55:04+00:00 2026-06-14T11:55:04+00:00

In it’s simplicity what I am trying to do is handle Doing Something by

  • 0

In it’s simplicity what I am trying to do is handle “Doing Something” by firing off a process on a seperate thread to do what I need to do and waiting for an event to be raised to say “I have finished doing what I need to do”. In the EventArgs though I will have a property for any errors which may be encountered during the process. Here is a simplified example of my situation.

public class MessageHandler
{
  private AutoResetEvent MessageHasSent = new AutoResetEvent(false);
  public void SendMessage()
  {
    MessageSender ms = new MessageSender();
    ms.MessageSent += new EventHandler<MessageSentEventArgs>(MessageHandler_MessageSent);

    Thread t = new Thread(ms.Send());
    t.Start();

    MessageHasSent.WaitOne();
    //Do some check here

    //Same again but for "Message recieved"
  }
  void MessageHandler_MessageSent(object sender, MessageSentEventArgs e)
  {
    if (e.Errors.Count != 0)
    {
      //What can I do here to return to the next step after waitone?
    }
    else
      MessageHasSent.Set();
  }
}
public class MessageSender
{
  public event EventHandler<MessageSentEventArgs> MessageSent;
  public void Send()
  {
    //Do some method which could potentiallialy return a List<Error>
    MessageSent(this, new MessageSentEventArgs() { Errors = new List<Error>() });
  }
}
public class Error { }
public class MessageSentEventArgs : EventArgs
{
  public List<Error> Errors;
}

Essentially once the event has been raised from Send the code will continute, however I want some way of the event giving feedback, potentially using the MessageHasSent. I have tried different methods, I thought if I called Close instead of Set it would perhaps allow me to access something such as IsClosed. You could throw an exception or set a flag outside of the scope of the event to check but I feel like this is dirty.

Any suggestions?

Using the TPL isn’t applicable in my case as I am using .NET 3.5.

  • 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-14T11:55:06+00:00Added an answer on June 14, 2026 at 11:55 am

    Since it seems that this entire section of code is already running in a background thread, and you’re doing nothing more than starting up a new thread just so that you can wait for it to finish, you’d be better off just calling Send directly, rather than asynchronously.

    • You don’t need to fire off an event when you’re completed.

    • You don’t need to signal the main thread when it needs to continue.

    • You don’t need to log the exceptions in a List, you can just throw them and catch them in SendMessage with a try/catch block.

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

Sidebar

Related Questions

I have thousands of HTML files to process using Groovy/Java and I need to
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
In my XML file chapters tag has more chapter tag.i need to display chapters
I am doing a simple coin flipping experiment for class that involves flipping a
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to select an H1 element which is the second-child in its group

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.