Open file while writing - possible Y/N?

 

Hi, 

if i open a file for writing in the OnInit, use a timer to write, then close the file OnDeInit, is there anyway i can view file (read-only) during EA run?

i keep getting:  "<file>.csv cannot be accessed. The file may bcorrupted, located on a server that is not responding, or read-only."

int OnInit()
  {
  EventSetTimer(10);
  filehandle=FileOpen("line5.csv",FILE_WRITE|FILE_CSV);
  if(filehandle!=INVALID_HANDLE)
   {Alert("FileOpen OK");}
   else {Alert("Operation FileOpen failed, error ",GetLastError());}
  }

void OnDeinit(const int reason)
  {
  EventKillTimer();
  FileClose(filehandle);
  }

void OnTimer()
  {
  FileWrite(filehandle,TimeToString(TimeCurrent(),TIME_MINUTES),current_profit);
  FileFlush(filehandle); 
  } 
 
 

Yeah you're right - I was crying too early: FILE_SHARE_READ did the trick..

int OnInit()

  {
  EventSetTimer(10);
  filehandle=FileOpen("line5.csv",FILE_WRITE|FILE_CSV|FILE_SHARE_READ);
  if(filehandle!=INVALID_HANDLE)
   {Alert("FileOpen OK");}
   else {Alert("Operation FileOpen failed, error ",GetLastError());}
  }

void OnDeinit(const int reason)
  {
  EventKillTimer();
  FileClose(filehandle);
  }

void OnTimer()
  {
  FileWrite(filehandle,TimeToString(TimeCurrent(),TIME_MINUTES),current_profit);
  FileFlush(filehandle); 
  }
 

hello, 

i am writing this as a warning, as I  do not know if you itentionally set the flags without FILE_READ; in the absence of it, each time you open your file, it will be emptied and that may not be a desired behaviour in case of a failure recovery and similar

Ok, so if you decide that you actually need it, make sure that you have to use FILE_READ in conjuction with  FILE_SHARE_READ 

best regards 

 
Demos:

hello, 

i am writing this as a warning, as I  do not know if you itentionally set the flags without FILE_READ; in the absence of it, each time you open your file, it will be emptied and that may not be a desired behaviour in case of a failure recovery and similar

Ok, so if you decide that you actually need it, make sure that you have to use FILE_READ in conjuction with  FILE_SHARE_READ 

best regards 

Hello Demos,

i'm afraid i don't understand: the behavior is fine, but you are right: if the EA opens the file for writing, it empties it. is that what you mean?  I don't see you point why FILE_READ should always be used in conjunction with FILE_SHARE_READ. While intuitively is sounds reasonable, i'm not sure what the difference would be for me as a 'back-door' user of the file while being written by the EA. 

Can you elaborate? 

Reason: