I want to store data asynchronously on the hard disk.
For this I use the following code:
Call in NT8:
Task t = Task.Run(() => { WriteAsyncNT8.WriteAsync(@"G:\mytest.txt", CurrentBar, newBar, CurrentBar, Time[0]); });
public async Task WriteAsync(string path, int Init, bool NewBar, int Value, DateTime datetime) { if (Init == 1) { File.Delete(path); } if (Init > 1 && NewBar) { StreamWriter sw; sw = File.AppendText(path); await sw.WriteAsync(Value.ToString() + "; " + datetime + ";" + Environment.NewLine); sw.Close(); } }
As a result I get corrupted data:
[COLOR=#c0392b][B]20; 10.01.2019 21:31:00; 20; 10.01.2019 21:31:00;[/B] [B]22; 10.01.2019 21:33:00; 22; 10.01.2019 21:33:00;[/B][/COLOR] 24; 10.01.2019 21:35:00; 25; 10.01.2019 21:36:00; 26; 10.01.2019 21:37:00; 27; 10.01.2019 21:38:00; 28; 10.01.2019 21:39:00; 29; 10.01.2019 21:40:00; 30; 10.01.2019 21:41:00; 31; 10.01.2019 21:42:00; 32; 10.01.2019 21:43:00; 33; 10.01.2019 21:44:00; 34; 10.01.2019 21:45:00; 35; 10.01.2019 21:46:00; 36; 10.01.2019 21:47:00; 37; 10.01.2019 21:48:00; 38; 10.01.2019 21:49:00; 39; 10.01.2019 21:50:00; 40; 10.01.2019 21:51:00; 41; 10.01.2019 21:52:00; 42; 10.01.2019 21:53:00; 43; 10.01.2019 21:54:00; 44; 10.01.2019 21:55:00; 45; 10.01.2019 21:56:00; 46; 10.01.2019 21:57:00; 47; 10.01.2019 21:58:00;
251; 10.01.2019 17:50:00; [COLOR=#c0392b][B]253; 10.01.2019 17:52:00; 253; 10.01.2019 17:52:00;[/B][/COLOR] 254; 10.01.2019 17:53:00; 255; 10.01.2019 17:54:00;
Thanks a lot for the support!
user10
Comment