Solved

VB File Errors between tasks in Win2000

Posted on 2006-06-21
4
161 Views
Last Modified: 2010-04-30
We are just converting application workstations to Windows 2000 and there seems to be a 'slowness' letting go of files in Win2000 that was not there in Win95.

Example:

VB Program does a shell to another program (3rd party product) and must wait until the other process completes: it does this by looking at the files created. Here is the code where it failed with an error #53 - File Not Found

    Do While Dir(mstrSwBundleFileName) = ""
        DoEvents
    Loop
    '-- Now wait until its size is non-zero
    Do While FileLen(mstrSwBundleFileName) = 0
        DoEvents
    Loop
   
In the above, only the file length command could get an 'error 53 file not found'


WHY is it that a DIR command returns the file name, then the FILELEN says file not found???
0
Comment
Question by:ruskker
  • 2
4 Comments
 
LVL 20

Expert Comment

by:alainbryden
ID: 16954054

no, file not found applies to the DIR function, because if it's asking what the directory of mstrSwBundleFileName is, and it finds out that mstrSwBundleFileName doesn't exist, then it can't return the directory so it will fail right there. This code should not be executing if mstrSwBundleFileName doesn't exist.
0
 

Author Comment

by:ruskker
ID: 16956273
Not so> The DIR function in VB returns a null string when the file is not found and it is used to test for just that.
By the way, this code has been running fine for 6 years on Win95 and this new behaviour started (inconsistently) on Win2000
0
 
LVL 1

Accepted Solution

by:
tguez earned 500 total points
ID: 17040245
Your code looks ok. I think the problem is that windows 2000 has a file write-caching.  So when files are writtin to the disk, the are not actually written right now, not necessarily.  Windows can cached them in memory, and then write then to disk later.

So, it could be that the dir command finds the file because it has started to be written into the directory table, but has not yet be actually written out into the disk. Or it has been partially written out to the disk, and not finished wirrtien completel,

So when you get to the filelen, you are getting an error.  

This is just an a tought.  I don't know if is correct, just a thought.

You can test if this is correct in a simple way.  Use the debug mode of visual basic.  Step throught the code.  When it goes out of the loop of the dir, then wait a few seconds until you are sure all the disk data has been written, look at the led of the harddirve.  Then continue to step through.  If what I say is correct, if you waited like 30 seconds, and then you do not get an error, then what i said is what actually is happenning.

If you still get the error, then what I said is not true.

But this could actually be the problem.  If the above works with you debug it and wait 30 seconds, perhaps you can just code in a certain time delay between the first loop and second loop.

Tomer

P.S.  Keep me posted what happens.

Another way to speed up the process is the above is correct, there is some API, look in the documentation, then causes windows to flush all write cache of all applictions.  You can call this function between the two loops.  The regular flush works for your program only, not for other programs.
0
 

Author Comment

by:ruskker
ID: 17063341
Tomer

Thanks - I think you are correct. Unfortunately I need to clear the cache of the other process, BUT, what I did was add some sleep time in between the 'dir' and the 'fillen' and after I closed a file to be used by another process. Since I set this time to 10 seconds I have not had the problem in 2 weeks.

Thanks..
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

929 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now