C# file not being written to until the application finishes running -


i've got set of specflow tests i'm running , i'm trying write results far file after each scenario finishes, , write again @ end of entire test run. if run tests in debug mode code hit after each scenario, file appears in windows explorer after tests finish (or force tests stop). code below, writes file in separate project specflow test project.

i not flushing , had in place of streamwriter:

using (var file = new fileinfo(filepath).appendtext()) 

but wasn't working, after looking various examples on internet added flush, close, process.start, changed streamwriter , none of them helped. current code still isn't working is:

    private string rootfolderpath = directory.getparent(@"..\..\..\..") +@"\";     public void writealltestscenarionames(list<scenarioresult> results, string filename, string directoryname)     {         results.sort();         directory.createdirectory(rootfolderpath + directoryname);         string filepath = rootfolderpath + directoryname + @"\" + filename;         using (var file = new system.io.streamwriter(filepath))         {             file.writeline(datetime.now.toshortdatestring() + " " + datetime.now.toshorttimestring());             foreach (var scenarioresult in results)             {                 file.writeline(scenarioresult.tostring());             }             file.flush();//flush file ensure it's written             file.close();//flush file ensure it's written         }         process.start(filepath);    //flush file ensure it's written     } 

in example i'm trying there 3 lines in output file when finishes , created, modified , accessed dates in file properties in windows explorer identical.

i using windows 7 enterprise sp1 64-bit .net framework 4.5.2

it seems file being written, issue wasn't showing in windows explorer. stepped through again in debug mode, checked in explorer, file wasn't there. copied file path variable's value , opened exact path in notepad++ , file there. following file showing in explorer , updating after each test scenario finishes.

edit: seems issue was

private string rootfolderpath = directory.getparent(@"..\..\..\..") +@"\"; 

was returning different result after each scenario after test run. 1 in root of user folder (correct) , other 3 directories above specflow project folder. in first folder it's outputting @ end, in second it's updating after every scenario.


Comments

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

mapreduce - Resource manager does not transit to active state from standby -

serialization - Convert Any type in scala to Array[Byte] and back -