.NET firmware in this code

Here is my code:

ThreadStart threadStart = controller.OpenFile;
Thread thread = new Thread(threadStart);
thread.Start();

      

In the OpenFile function, my code looks like this:

System.Console.Error.WriteLine("Launching");

      

The code in OpenFile doesn't execute for 30 seconds exactly. It starts right away on my machine, but in our production environment it takes 30 seconds before this print statement executes.

Is there a setting or something that can do this? Where would I start looking?

+1


source to share


8 answers


As others have pointed out, first try building a test program that demonstrates the behavior.

If you can't, try to fix the problem: 1. Call the method directly, not on a stream, and see how it behaves. 2. Comment out the rest of the code except for the System.Error.WriteLine



If you still see latency in (1) but not in (2), try connecting to the AppDomain.AssemblyLoad Event . I've seen this happen when there is a web service call in the called method (it generates a serialization assembly on the fly, so it takes time), or if there is a first reference to an external assembly and it takes a while to find and load it. This is very rare, but I had to deal with it, so it's worth giving it a try.

+1


source


Are you having the same problem if you are using other streaming methods (like Threadpool)? This will tell if it's related to this streaming method or all methods. Also, is the WriteLine statement the only statement in your OpenFile procedure? 30 seconds is the total length of the timeout, so maybe what is happening here.



Other than that, I'm not sure why the thread handler would stop for 30 seconds before processing.

+1


source


Unfortunately jeremyZX replied in a comment so it cannot be upvoted, but "If you are looking for output to a log file, there might be a 30 second timeout for someone who has a tracer that you are working with before the entries are dumped" is worth a look. Anytime you see human latency in the system, the timeout related code is one of the first things to check. Especially if you see a delay that falls for a while, equal to as much as 10, 30, 60 seconds ...

+1


source


My first step would be to create a test version of the application that calls the OpenFile function in the normal way (without using threads) and see if you still get latency.

0


source


I cannot reproduce this problem. The following program does not suffer from a 30 second delay:

using System;
using System.Threading;

namespace Net_Threading_Problem
{
    class Program
    {
        static void Main()
        {
            Controller controller = new Controller();
            ThreadStart threadStart = controller.OpenFile;
            Thread thread = new Thread(threadStart);
            thread.Start();

            thread.Join();
        }
    }

    internal class Controller
    {
        public void OpenFile()
        {
            Console.Error.WriteLine("Launching");
        }
    }
}

      

Could you provide more context? Ideally, a short but complete program that demonstrates the problem.

And has no compilation errors ...

0


source


Does your application need to load other assemblies into memory, assemblies that might be in memory on your computer already? .NET applications don't start instantly, and more assemblies mean more load times. You can try pre-compiling with Native Image Generator .

0


source


You may be experiencing thread dizziness, which means that your thread is not receiving quanta of execution because there are higher priority threads in your process. If this higher level flow is only present in your production environment and not in your test environment, this could be the reason for different results.

0


source


Sometimes the output (Console, StreamWriters, etc.) can be delayed due to flushing issues. If you can, use a better logging framework like log4net or NLog, which will record the timestamp at which the method is actually called. I sometimes use log4net's "OutputDebugString" function in conjunction with SysInternals' DebugView for more realistic output, although even this is susceptible to timing delays.

The problem you are describing is like tweaking caching or performance, and I suspect it is indeed triggered instantly.

0


source







All Articles