12-02-2015 06:14 PM
Yes, each operation takes 100ms, but several instances can be run in parallel, giving a proportional speedup, so that is a partial solution if many files need to be checked. The individual operation still has a fixed duration.
12-02-2015 07:01 PM
@altenbach wrote:
@BowenM wrote:
I did a test on my machine out of curiosity. 100ms seemed like a long time to just open / close a file.
The way I understand the problem, the 100ms delay occurs if we try to open a file that has already been opened elsewhere.
I missed that part of it. I had a couple open files to make sure that it detected them as open but most were closed.
Just FYI I also tested this with a call to the System.FileIO .NET and it was slightly slower. I think hoovah's suggestion is your best bet.
12-03-2015 01:15 AM
12-03-2015 01:16 AM
12-03-2015 01:37 AM - edited 12-03-2015 01:48 AM
Most likely not without diving quite deep into Windows API calls. The most common way to check if a file is still opened in another application is by trying to access it. Windows seems to have a built in retry mechanisme when that call fails. There is no easy way to disable that. If I understand the post from BowenM correctly this same thing happens in .Net too, hinting at the fact that it is a Windows thing.t
You could try it yourself by calling the Windows API CreateFile() directly to see if that shows the same delay. Ultimately that is the function that the LabVIEW OpenFile function calls internally too. If CreateFile() shows this same bahviour it's probably going to be a though cookie to work around this and a review of what you are wanting to do is required.
Hmm, you have a good chance that calling CreateFile() directly is going to help here. I found in some old documents that the LabVIEW FileOpen function internally calls CreateFile() multiple times when it fails because otherwise it would randomly fail for MS utilities like FindFast and similar accessing files in the background for indexing purposes. This is at the same time another issue: CreateFile() failing doesn't necessarily mean that your other application has the file still open. It could be also some file indexing service that is opening the file to see if there is something to add to the search index.
So while calling CreateFile() directly is a workaround for the problem at hand, it is not a proper solution. Rather than causing long delays when trying to open an already open file it can give you false positives and is prone to race conditions too. The CreateFile() call can succeed but immediately thereafter the other applciation opens that file and your conclusion is now invalid.