c# - Text Writer is already closed in a Delay Timer "Tick" Event -
i'm trying utilize delay timer on windows form. want avoid thread.sleep want controls active during delays. right have button starts code on click. opens stream , writes title line in csv. delegate timer tick have if check box checked, it'll stop timer, otherwise writes new line. after that, timer started. author isn't closed until after timer executes. so, like,
filestream mydata = file.openwrite("myfile.csv"); textwriter mywriter = new streamwriter(mydata); mywriter.write("titles,go,here\n"); int x = 0; delaytimer.tick+= delegate { if (checkbox.checked) { delaytimer.stop(); } mywriter.write(x+"stuff\n"); x++; }; delaytimer.start(); mywriter.close();
however, whenever seek execute, freezes after button press , visual studio informs me streamwriter closed. i'm not sure how prepare this, thought code execute timer before proceeding unless don't understand how it's executing timer.
you have notice close stream after dlay starts, when tick occurs stream closed. seek close stream within anonymous delegate when job stream done.
excuse bad english. hope helped you.
c# timer
No comments:
Post a Comment