file locks

 

I have a simple MQL4 program that creates a simple one line text file for each minute with the datetime/open/high/low/close values.  I then have a C# program that copies the output file from MQL4 to a network directory so that a secure/isolated pc can process the values in a database.  At the end of my MQL4 code I do close the file handle but yet I still occasionally get a file lock error from the C# program.  Is there any chance that MQL4 is not releasing the file lock or anything I can do to confirm that the file lock is released?



   ins=StringConcatenate(tmstr,",",iOpen("GBPUSD",PERIOD_M1,shift),",",iHigh("GBPUSD",PERIOD_M1,shift),",",iLow("GBPUSD",PERIOD_M1,shift),",",iClose("GBPUSD",PERIOD_M1,shift));
   Print(ins);
   FileWriteString(hndl,ins);
   FileClose(hndl);
 

jshumaker: Is there any chance that MQL4 is not releasing the file lock

or anything I can do to confirm that the file lock is released?

  1. No.

    How To Ask Questions The Smart Way. 2004
              Don't rush to claim that you have found a bug.
    Questions Not To Ask
              My program doesn't work. I think system facility X is broken.

  2. The lock has been released when you can open it with the C#.

  3. You have a race condition; you have no coordination between MT4 and C#. The simplest solution is to write the file with a ".TMP" extension, close it, then rename it so C# can see it and open it;.
 
William Roeder:
  1. No.

    How To Ask Questions The Smart Way. 2004
              Don't rush to claim that you have found a bug.
    Questions Not To Ask
              My program doesn't work. I think system facility X is broken.

  2. The lock has been released when you can open it with the C#.

  3. You have a race condition; you have no coordination between MT4 and C#. The simplest solution is to write the file with a ".TMP" extension, close it, then rename it so C# can see it and open it;.

I didn't think about renaming the file.  Thank you