user477928
user477928

Reputation: 61

how to make sure the share path exist, if not, return false in time

I want to know whether the share path exist,maybe the Directory.Exists(string path) is not a good method due to wasting about 20 seconds when return false. Is there a way to return "true or false" whether the share path exist in time(for example. 1 or 2 second)

Upvotes: 0

Views: 632

Answers (2)

Nick Martyshchenko
Nick Martyshchenko

Reputation: 4249

Try method described here (it rely on http://msdn.microsoft.com/en-us/library/aa394435(VS.85).aspx)

Also, to decrease response time you can do some check prior really checks share.

BTW, why so weird response time? Do you make check over slow Internet connection (VPN) or your network so slow?

Also you can try this method but it requires PInvoke (here details), so first method is preferable.

And you can check is there network available via

System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable()

before do any further checks or maybe some more network checks (see here) e.g. ping host to check its availability and after all check for network share.

If you want to do it in background than you can follow Albin Sunnanbo's advice

Upvotes: 0

Albin Sunnanbo
Albin Sunnanbo

Reputation: 47038

You need to run Directory.Exists in a separate thread and implement the timeout yourself.

Call Thread.Join(TimeSpan ts) with your timeout.

Upvotes: 1

Related Questions