1

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.

Jason Evans
  • 28,906
  • 14
  • 90
  • 154
  • How exactly does it not work? What *does* it do? – svick Mar 24 '14 at 13:19
  • it just checks a directory on the network path, if it exists then ok, if the network drive for some reason not ready it will wait for response for 5 sec then assume not ready ! – Ali Alnakeab Mar 24 '14 at 13:37
  • That sounds like a problem in the `CheckNetworkDriveMethod()` method, not related to the code you posted. – svick Mar 24 '14 at 15:37
  • no,if i remove the parallelism and call the method directly it returns true ! and even with the task in single process everything is fine ! – Ali Alnakeab Mar 24 '14 at 16:12

1 Answers1

1

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()

Community
  • 1
  • 1