[02/03] IO.File.Exists() too slow
Hello,
I recently changed workstations. My old WorkStation was WS63, my new one is WS130 (not that it matters, but I didn't feel like coming up with fake numbers). Anyway, part of my program is looking for files on WS63 (which is no longer in use). Using
IO.File.Exists("\\WS130\c$\asdf.bmp")
returns true/false immediately, however
IO.File.Exists("\\WS63\c$\asdf.bmp")
is taking somewhere around one minute before returning false.
Does anyone know of a better way to check to see if a file exists?
Thanks.
Re: [02/03] IO.File.Exists() too slow
The delay is caused by the function timing out eventually.
try pinging the WS63 workstation before you even try to see if a file exists on it. If you can't even see WS63 then you know you wont be able to look for files on it.
Although I have to ask, if WS63 is no longer in use, then why are you even looking for files on it in the first place?
Re: [02/03] IO.File.Exists() too slow
Quote:
Although I have to ask, if WS63 is no longer in use, then why are you even looking for files on it in the first place?
Aha!
Sorry. Someone (me, in this case) "attached" a file on my desktop to an object in our program. "Attachments" can come from anywhere. Now, I have a new workstation, but those records still exist in our DB, still pointing to my old workstation. Part of the program checks to see if the file exists and changes the icon to a red X or something like that if it doesn't. I am getting the red X, but it is taking forever.
Assuming this happens to someone in the company (fairly likely), or the location (hopefully as central as possible) of the attachments folder(s) changes, they can use another form repair all those broken links. For instance, all of my \\WS63\c$\Desktop attachments need to be changed to \\WS130\c$\Desktop. Too much info, I guess, but thanks for the ping idea.
How would I do that, by the way? I am going to search the forum, but I thought I might as well ask in case I can't find anything.
Re: [02/03] IO.File.Exists() too slow
hmmm.. well the .NET 2.0 framework has a nice ping class all built in.
Since you are using 1.1, that is not going to be available to you to make your life easier ;)
Someone who still uses 1.1 might come up with a better solution for you.
Two that I can think of are:
1) Use code to check once for the workstations availability, and set a boolean flag you can check to see if you should even bother checking for the existance of the file
Code:
If IO.Directory.Exists("\\WS63\c$") Then
End If
This would likely take the same amount of time it would to check for a file that isnt available on the network, but at least it would only be done once, instead of once for EACH file.
2) Use the cmd prompt ping.exe command line utility, and redirect its output as a stream to your app so that you can parse it and see what he result of the ping was. (this is actually easier than it sounds)
Re: [02/03] IO.File.Exists() too slow
Well, after considering the options, I think I am going to query the active directory to see if the machine exists. I can't be sure how long to set the timeout for pinging, and that could end up taking just as long, I think. So, I'm just going to store all the machine names in a dataset and compare against that.
Re: [02/03] IO.File.Exists() too slow
Yeah if you have access to active directory then that could make it easier on you.
Re: [02/03] IO.File.Exists() too slow
Quote:
If IO.Directory.Exists("\\WS63\c$") Then
End If
I was actually doing that first in one part of the program, and getting the same results.
Re: [02/03] IO.File.Exists() too slow
Quote:
Originally Posted by kleinma
Yeah if you have access to active directory then that could make it easier on you.
What do you mean, exactly? I mean, if a user can't see anyone, my query to the active directory will just return nothing, right? It won't break, will it? In which case, all links would appear broken (which is how it SHOULD work).
Re: [02/03] IO.File.Exists() too slow
OK, I queried the active directory and put all the names into a dataset. Problem is, when I sorted the list, I noticed that WS63 (my old workstation, which is setting next to me right now... unplugged) is still showing up. I have a sub that prints all properties the query returns, and I can't see a difference between WS63 and WS130 (my current workstation). If I attempt to Map a Network Drive, I can't see WS63. Also (and this is VERY important) I am instantly given a list of all possible workstations. I guess it is possible that Windows gets this list when I log on. Does anyone know how to access that list? Or, is there a way to quickly tell if a workstation is still available without pinging it?