JamesKillian
asked on
Extreme slowdown when accessing files over the network through VB when using an XP machine.
One part of my program checks the status of various files on other machines over a corporate network as a means of tracking progress on on a centralized machine. One of the issues that I never was able to resolve when using a Win98 box was having to manually open a connection to each machine (open a folder on each machine even though the folder share passwords were stored). When trying to access files in shared folders it would just come up as unavailable if I tried doing from within the VB program if I had not yet manually opened the shared folder.
Well now with WinXP it no longer does this, however that issue has now been replaced with a much more annoying one. Where before access was instant, it now takes 20-30 seconds to open a connection to any of the other machines (that is it no longer makes me manually open a folder, but now it basically locks up while it waits for 20+ seconds for the network connection to complete and the files to become accessible).
I realize this may not be the best forum to ask this question, since I also experience the slowdown when trying to open a shared folder outside of VB using an XP machine, but I thought perhaps someone might know a more direct way of checking a file across the network than what I'm using which would bypass this slowdown (or ideally something to reduce the lag). While I would like to read data from text files instantly without delay, it would suffice if I could at least know whether a named file exists in a given shared folder. Oddly this delay also crops up if there isn't constant communication as well. That is if a few minutes pass without accessing the shared folder, I incurr the long delay once again on the next attempt at access.
Public Function FileExist(strPath As String) As Boolean
'Check whether a file exists/can be accessed
Dim X As Integer
X = FreeFile
On Error Resume Next
Open strPath For Input As X
If Err = 0 Then
FileExist = True
Else: FileExist = False
End If
Close X
End Function
Well now with WinXP it no longer does this, however that issue has now been replaced with a much more annoying one. Where before access was instant, it now takes 20-30 seconds to open a connection to any of the other machines (that is it no longer makes me manually open a folder, but now it basically locks up while it waits for 20+ seconds for the network connection to complete and the files to become accessible).
I realize this may not be the best forum to ask this question, since I also experience the slowdown when trying to open a shared folder outside of VB using an XP machine, but I thought perhaps someone might know a more direct way of checking a file across the network than what I'm using which would bypass this slowdown (or ideally something to reduce the lag). While I would like to read data from text files instantly without delay, it would suffice if I could at least know whether a named file exists in a given shared folder. Oddly this delay also crops up if there isn't constant communication as well. That is if a few minutes pass without accessing the shared folder, I incurr the long delay once again on the next attempt at access.
Public Function FileExist(strPath As String) As Boolean
'Check whether a file exists/can be accessed
Dim X As Integer
X = FreeFile
On Error Resume Next
Open strPath For Input As X
If Err = 0 Then
FileExist = True
Else: FileExist = False
End If
Close X
End Function
ASKER
Thanks for the reply, it has the same amount of delay though, I made a quick test and it takes the same amount of time either way.
I'am sorry but i don't now what else you can try.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Hi JamesKillian,
This old question (QID 20561323) needs to be finalized -- accept an answer, split points, or get a refund. Please see http://www.cityofangels.com/Experts/Closing.htm for information and options.
This old question (QID 20561323) needs to be finalized -- accept an answer, split points, or get a refund. Please see http://www.cityofangels.com/Experts/Closing.htm for information and options.
Please let me now if you've got a question about the code or let me now how this is working for you.
Gertjan
Public Const INVALID_HANDLE_VALUE = -1
Public Type WIN32_FIND_DATA
dwFileAttributes As Long
ftCreationTime As FILETIME
ftLastAccessTime As FILETIME
ftLastWriteTime As FILETIME
nFileSizeHigh As Long
nFileSizeLow As Long
dwReserved0 As Long
dwReserved1 As Long
cFileName As String * MAX_PATH
cAlternate As String * 14
End Type
Public Declare Function FindFirstFile Lib "kernel32" _
Alias "FindFirstFileA" _
(ByVal lpFileName As String, _
lpFindFileData As WIN32_FIND_DATA) As Long
Public Declare Function FindClose Lib "kernel32" _
(ByVal hFindFile As Long) As Long
Public Function FileExists(strPath As String) As Boolean
Dim WFD As WIN32_FIND_DATA
Dim hFile As Long
hFile = FindFirstFile(strPath, WFD)
FileExists = hFile <> INVALID_HANDLE_VALUE
Call FindClose(hFile)
End Function