Can't read network path?

  • Thread starter Thread starter Brett Romero
  • Start date Start date
B

Brett Romero

I'm running the code below to get network paths.

DirectoryInfo diSource = new DirectoryInfo( fullPath );

They usually look like this:

\\cpx-270\SomeFolder

I may or may not have access to SomeFolder. Sometimes the machine
isn't on or the folder is spelled "SomeFolders" on a particular
machine. It seems when I run across those scenarios, my app hangs and
I get this error:

LoaderLock was detected
Message: Attempting managed execution inside OS Loader lock. Do not
attempt to run managed code inside a DllMain or image initialization
function since doing so can cause the application to hang.

Any one know how I can avoid this?

Also, it may take a little time to get the network path assigned to
diSource. I'd like to stall until that variable has a value. So I
need some type of synchronous contraint before moving on. Any
suggestions here as well are appreciated.

Thanks,
Brett
 
chanmm said:
Sounds like you can only put an exception handle on it.

Exception handling doesn't really help. I still have to wait a while
until the exception is thrown. Is there a way to time out the code
block?
 
Here's the fix - Ping the machine first:

Ping netMon = new Ping();

PingReply response = netMon.Send(ComputerName, 4);

if (response.Address != null)
networkAccess = true;
else
{
networkAccess = false;
sb.AppendLine("Not online");
}

These are in System.Net.NetworkInformation namespace.

Brett
 
| Here's the fix - Ping the machine first:
|
| Ping netMon = new Ping();
|
| PingReply response = netMon.Send(ComputerName, 4);
|
| if (response.Address != null)
| networkAccess = true;
| else
| {
| networkAccess = false;
| sb.AppendLine("Not online");
| }
|
| These are in System.Net.NetworkInformation namespace.
|
| Brett
|

A ping won't help if the server name or share name is mispelled, or if the
"Server" service is not running or if something else is wrong higher up in
the network stack.
Ping only tells you that the remote server's network stack is reachable up
to and including the IP layer. Note also that firewalls and routers may
prevent passing ICMP packets, so ping won't help in such environments
either.

Willy.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top