Question

I have this function that executes an async task run and return results

 public bool CheckNetworkDrive(string drive)
 {
    var task = new Task<bool>(() => { return CheckNetworkDriveMethod(drive); });

    task.Start();

    //make async call to check network path to avoid lock in case of not exist 
    if (task.Wait(5000) && task.Result)
        return true; 
    return false;
 }

in local host everything works fine but in webgarden its not seems to work and I can’t figure the exact reason, so can you help or suggest an alternative !

ps, the check method will check network path, if it’s not responding it will block the whole code, so that why I need fire and async wait method.

Was it helpful?

Solution

sorry for inconvenience, it turned out that the problem is not with the parallel task in particular,I'm using window identity impersonation to access network drives and somehow the task is seems to lose impersonation so after I passed the impersonated user to the task everything worked fine.

I found this that helped

How do I set the user identity for tasks when calling Task.WaitAll()

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top