LOCK FILES

  • Thread starter Thread starter James
  • Start date Start date
J

James

is there a 3rd party tools or simple batch scripts or VB.NET 2003 to lock
files
? Here is the problem

1. i've a config.ini FIXED in a local directory eg c:\configuration. Only
this file exist in this directory.
2. the contents of config.ini is follows

key=country_code

3. The vendor software i m using only recognise c:\configuration\config.ini
as parameters as the vendors told me that the path is hard-coded in the
above directory.

4. i've many countries and each key represents different countries. If i run
the software in many physical machines, it works because there can never be
contention of the config.ini file. However if i want to save costs and run
the program on ONE machine only, i must create a batch file or script to
check whether config.ini is currently in use. If not in use, the program can
use this file and run. If in use, wait for x minutes before re-try.

5. How shld i approach the above problem ?
 
In .net you could do something like this to check every minute if a file is
in use, just try to open it in a try catch block:

Dim myReader As IO.StreamReader
Dim myFile As String = "c:\configuration\config.ini"
If System.IO.File.Exists(myFile) Then
Do
Try
myReader = New IO.StreamReader(myFile)
myReader.close
'startYourProgram
Exit Do
Catch
Threading.Thread.Sleep(60000)
End Try
Loop
Else
MessageBox.Show(myFile & ": does not exist")
End If

hth Greetz Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top