-3

i need to write data into a CSV file each 600 msec using a c# application . The question: is better open and close file each time or keep it open until the end of write data actions? Note: i will change file name each day and each 60000 record

Thanck a lot for your opinions

jumpier
  • 29
  • 1
  • 6
  • Best way is to use the oledb interface to perform read/writes which doesn't technically open the file. Oledb treats the csv file as a database which is faster than opening the file. See posting : http://stackoverflow.com/questions/6813607/parsing-csv-using-oledb-using-c-sharp – jdweng Dec 03 '16 at 09:38
  • @jdweng _"Oledb treats the csv file as a database which is faster than opening the file"_ - what? – CodeCaster Dec 03 '16 at 11:30
  • Absolutely correct. Access and Excel are databases and the oledb (or ACE on newer version of Access and Excel) are read by accessing the sectors in the disk and not using the open file system method. With CSV the same is done. – jdweng Dec 03 '16 at 11:46
  • @jdweng citation needed. – CodeCaster Dec 03 '16 at 12:13

1 Answers1

-1

CSV files are really easy to write to. If you don't know how to write to a file, the dotnetperls is your friend. You can simply call BinaryWriter.Write() to write anything. Write a value then a comma. That's it! If this file is going to be edited by the user at the time of running the application, then don't keep it open. Otherwise, keeping it open makes sure nothing unexpected happens.

None
  • 609
  • 7
  • 22