Quantcast
Channel: Common Language Runtime Internals and Architecture forum
Viewing all articles
Browse latest Browse all 1710

Failed to start a new STA thread

$
0
0
Hi!

We are having some really weird failures where a .NET 1.1 dll fails to start a new STA thread. The weird part is that the caller does not get any kind of exception (except the one that we are throwing because the resetEvent.WaitOne won't succeed within 5 minutes).

The method is called from a Biztalk 2004 orchestration. The worker thread does use a 3rd party com-dll that won't work in MTA.  

Here is a short code snippet to show what we are trying to do.

    public abstract class MyBaseClass
    {
        private ManualResetEvent resetEvent = new ManualResetEvent(false);

        protected void Execute()
        {
            try
            {
                Thread STAThread = new Thread(new ThreadStart(RunCommand));
                STAThread.ApartmentState = ApartmentState.STA;
                STAThread.Name = "STA worker";

                STAThread.Start();

                if (!resetEvent.WaitOne(new TimeSpan(0, 0, 5, 0, 0), false))
                {
                    throw new ApplicationException("Thread did not respond within timeout limit");
                }
            }
            catch (Exception ex)
            {
                // dumping of the exception to the eventlog omitted for brevity
                throw;
            }
        }

        private void RunCommand()
        {
            try
            {
                /*
                 * this  is where the real work is done
                 */ 
            }
            catch ( Exception ex)
            {
                // dumping of the exception to the eventlog omitted for brevity
                throw;
            }
            finally
            {
                resetEvent.Set();
            }
        }
    }


I've added a lot of debugging code the that function. It shows that most of the time the function works fine but a few times a day the child-thread just don't start.

We've also noticed that quite often it takes a few seconds before the runcommand delegate really does anything.

Do you have any idea what could cause this and how to investigate this further?

With regards

Tapio Kulmala

Viewing all articles
Browse latest Browse all 1710

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>