tags:

views:

254

answers:

3

My win32 C++ application frequently checks a file that normally resides on a network share [in our corporate network]. But if the computer isn't connected to a network, the application freezes for several minutes and the user usually has to end the process. How can I check if the file is accessible before I open it?

Checking if any network connection exists may not be good enough. The reason the users disconnect is to use to a test network where the file does not exist.

+1  A: 

Put the file access into a seperate thread?

Richie_W
I was about to suggest the same thing :-)
Jon Cage
A: 

It seems to me this method in a separate thread would be your best bet.

File.Exists

Chris J
+1  A: 

I think a thread is your best option.

There does not appear to be a way to invoke the CreateFile API asynchronously. Once a file handle is open you can do asynchronous I/O on it, but the act of opening it is still synchronous.

You will have to manage the synchronization with the thread yourself since only your app knows when it needs the result of the fopen, and it may still end up blocking at that point.

Rob Walker