0

I am currently having some issues with the intranet and some network drivers usually start to hang after a while

I did the following code in order check async if the given path is accessible or not but now there seems to be a new issue. Sometimes the task doesn't start at all, and on break it says that its queued to start. This happens only on few machines, not on all, that's why the confusion

public static class PingHelper
{
    private static Task RealTask { get; set; }
    public static bool IsAvailable { get; set; }

    public static async Task Check(string location, int timeout)
    {
        if (RealTask == null)
        {
            DirectoryInfo directoryInfo = new DirectoryInfo(location);

            RealTask = Task.Run(() =>
            {
                var result = directoryInfo.Exists;
            });

            Task dummyTask = Task.Delay(timeout);

            if (dummyTask != await Task.WhenAny(RealTask, dummyTask))
            {
                RealTask = null;
                IsAvailable = true;
            }

            return;
        }

        if (RealTask.IsCompleted)
        {
            RealTask = null;
        }

        IsAvailable = false;

    }

}

The code should create a task, check after x miliseconds if it returned successfully or not, also if a task is already existing an hanging on Directory.Exists, just assume its still hanging and return false immediately.

So basically I am not sure what is the root cause of the problem, the ThreadPool is set to 1024 and during break there are like only 3 tasks running, so it wont be case of overpopulating tasks

Andrei Don
  • 47
  • 6

0 Answers0