简体   繁体   中英

Why do some applications lock files and others don't?

In my datalogging application I write to a temporary file of the form ... AppData\\Local\\Temp\\euaxgd5z.csv

This opens by default in Excel.

Process.Start(TempFileLocationBox.Text.ToString());    

The next time the timer tries to write more data to this file, an exception is thrown. However if I open it with TextPad

Process.Start("textpad.exe", TempFileLocationBox.Text.ToString());    

it can write to the file quite happily and TextPad will ask if I want to reload it. How can I get Excel to behave as nicely as TextPad?

Personally, I wouldn't even try to 'communicate' to excel the fact that you want the file reloaded. I would just write a new file and open a new copy of excel, after closing the old copy if possible.

That way you won't need to worry if the user is using open office instead, for example.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM