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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T04:39:47+00:00 2026-05-23T04:39:47+00:00

I have a Windows service written in C# that spawns several worker threads. Those

  • 0

I have a Windows service written in C# that spawns several worker threads. Those threads are supposed to loop every X minutes until the service is stopped, which works very well in most cases. But, there is one thread that appears to be stopping for no reason. We already have a try/catch block with logging code around the thread’s entire function, but it never logs any exceptions.

In .NET, is there any way to monitor a thread from another process and record when/why/how it stopped?

More details

The code that spawns the thread looks like this:

try
{
    // Create a new thread for processing Incoming Emails
    IncomingEmailThread = new Thread(new ThreadStart(ProcessIncomingEmails));
    IncomingEmailThread.Start();

    LogEvent("Service Started", EventLogEntryType.Information);
}
catch (Exception e)
{
    LogEvent(e.Message, EventLogEntryType.Error);
}

And the code inside the thread looks like this:

while (!Closing)
{
    try
    {
        // Wait for 5 minutes before running.
        InterruptableSleep.WaitOne(300000, false);

        // Process the incoming email for all instances
        string[] Instances = Settings.GetAllInstances();
        foreach (string Instance in Instances)
        {
            Logic.IncomingEmail IncomingEmailInstance = new Logic.IncomingEmail(Instance);
            IncomingEmailInstance.CreateRecordsFromIncomingEmail();
        }
    }
    catch (Exception ex)
    {
        // Log the exception and then eat it so it doesn't stop the thread
        LogEvent(ex.Message + "\r\n" + ex.StackTrace, EventLogEntryType.Error);
    }
}

The problem is not caused by the Closing flag, because this loop usually runs for several days before it stops working. The problem is not an exception inside CreateRecordsFromIncomingEmail(), because the catch block has not logged any exceptions. Our logging code writes directly to the Windows event log, we use it throughout the product, and it is very reliable.

Unfortunately, we can’t use a debugger, because we’ve only seen the problem on one production server. We haven’t been able to reproduce it in dev, or on any other servers.

  • 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-23T04:39:47+00:00Added an answer on May 23, 2026 at 4:39 am

    We never did find a solution, but the problem stopped happening. We decided to just add some logging code in case it ever happens again.

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

Sidebar

Related Questions

We have a Windows Service written in C#. The service spawns a thread that
I have written a Windows service that spawns a separate process. This process creates
I have a windows service written in C# that acts as a proxy for
I have written a Windows service that allows me to remotely run and stop
I have a server written in Java that runs as a Windows service (thanks
I have a windows service written in C# that creates a truck load of
I have a Windows Service written in C# that handles all of our external
Scenario I have a windows service written in C# that performs some processing based
I have Windows Service written in C#. It starts two threads, one is pooling
We have an windows service written in .net, that is hosting WCF service. My

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.