System.InvalidOperationException occured

-2

I was trying to save some data to csv file, but I always get System.InvalidOperationException, please look at my code, what am I doing wrong

private void ButtonSave_Click(object sender, RoutedEventArgs e)
    {

        double[,] data = new double[10000, 650];
        string fileName = @"C:\Users\iql-laptop\Documents\CDL-Windows-1.0.1\CDL-Windows-1.0.1\Samples\test.csv";
        using (FileStream fs = new FileStream(fileName, FileMode.OpenOrCreate))
        {
            using (StreamWriter outfile = new StreamWriter(fs))
            {
                for (int x = 0; x < 10000; x++)
                {
                    string content = "";
                    for (int y = 0; y < 650; y++)
                    {
                        content += data[x, y].ToString("0.00") + ";";
                    }
                    outfile.WriteLine(content);
                }
            }
        }
    }

System.InvalidOperationException HResult=0x80131509 Nachricht = Synchronous operations should not be performed on the UI thread. Consider wrapping this method in Task.Run. Quelle = System.IO.FileSystem Stapelüberwachung: at System.IO.WinRTFileSystem.EnsureBackgroundThread() at System.IO.WinRTFileSystem.Open(String fullPath, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, FileStream parent) at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options) at System.IO.FileStream..ctor(String path, FileMode mode) at WillDevicesSampleApp.RealTimeInkPage.ButtonSave_Click(Object sender, RoutedEventArgs e) in C:\Users\iql-laptop\Documents\CDL-Windows-1.0.1\CDL-Windows-1.0.1\Samples\WillDevicesSampleApp\RealTimeInkPage.xaml.cs:line 231

c#
asked on Stack Overflow Jul 15, 2019 by Emil_Bayt • edited Jul 15, 2019 by Amy

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0