c# - My System.IO.File.WriteAllText coding doesn't create a file after it has once been deleted in Windows Explorer -


conclusion @ bottom of post

i'm novice c# , have begun using system.io, haven't been able find information on issue wanted ask guys here:

i have program when run, creates directory, writes .txt file recent value of variable was, if program interrupted or computer loses power, restarting program retrieve stored number .txt file.

i've done this:

    string instatr = lastvalue.tostring();     system.io.file.writealltext(@"c:\\dottempfiles\\"+instrument.name+"atr.txt", instatr); 

my first time running program, file created, , found on every cycle number in file being overwritten last valid number wanted.

however, once went dottempfiles directory , deleted .txt file using shift+del, file has never returned upon running program thought would. if delete entire directory , run program, directory recreated still not file.

if run program using different instrument.name, new file created expected, original 1 once manually deleted still not showing, after computer restarts.

i can't find information leads online, have idea? thank you!

edit (more info): people asked few questions i'm adding more information (thank you)

there no errors being reported. compiles fine, , when running, there output window alerts me errors if reference object null, or try read empty file, etc. no errors occurring.

more background on program is. there stock trading program called ninjatrader has own api based on c#. wouldn't support questions have because it's outside normal scope of script development intended people use, , that's ok me. program trading strategy run within ninjatrader, , exposes default programmer access these 2 main methods:

initialize()

protected override void onbarupdate() //this main part of program gets called every time change has occurred 1 of bars on stock chart.

in variable declaration section have this:

    system.io.directoryinfo di = directory.createdirectory(@"c:\\dottempfiles"); 

and in onstartup() have this:

    //set readme file in temp directory in case people wonder why keeps appearing     string readme = "this dottempfiles directory created strategy every time run, , temporary text files name [instrumentsymbol]atr.txt written containing last highest atrstopvalue strategy, if stopped , restarted open position, read file best value instead of recalculating possibility of lower unwanted value.";     system.io.file.writealltext(@"c:\\dottempfiles\\readme.txt", readme); 

every time onbarupdate() called, can few times per second, first calculates double called lastvalue number related stock price, converts string instatr, writes .txt file.

    string instatr = lastvalue.tostring();     system.io.file.writealltext(@"c:\\dottempfiles\\"+instrument.name+"atr.txt", instatr); 

and every single piece of code have connected issue. mentioned above, created file first time, since i've deleted file in windows explorer, isn't able recreate it. however, deleting directory , restarting strategy program recreate directory.

ontermination() not being used close or delete file in way (just in case people wanted ask) -- not using other code interact file ones shown. thanks!

edit 2 (update after reading comments): thank guys comments , help. i'll when home try recreating minimal version of empty program containing these lines of code , see outcome is, , i'll post updates in either way.

edit 3: thank steve, idea should use on these kinds of things.

edit 4 (conclusion): well, found out overlooked simple own code logic. setting file.writealltext trigger time double variable increased in value, not on every call of onbarupdate method. because of this, file not written except once every few hours or , see working properly. sorry made these people read post since based on issue of own fault. however, thankful comments helped me point, , steve , mark lakata tips learned new things from.

i found out there nothing wrong file creation, fact coding logic calling far less assumed (once every few hours vs several times per second)


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -