Whats wrong with my backgroundwork method

Posted by diver-d on Stack Overflow See other posts from Stack Overflow or by diver-d
Published on 2010-03-21T04:44:54Z Indexed on 2010/03/21 4:51 UTC
Read the original article Hit count: 361

I am trying to get a background worker process working in a wpf application. it creates 2 files then crashes.

   BackgroundWorker worker = new BackgroundWorker();
                        worker.DoWork += delegate(object s, DoWorkEventArgs args)
                        {
                            CreateFile(i.ToString());
                        };
                        worker.RunWorkerAsync();


private void CreateFile(string fileName)
    {
        string path = string.Format(@"{0}\{1}.txt", directory, fileName);
        using (StreamWriter sw = new StreamWriter(path))
        {
            sw.WriteLine(fileName);
        }
    }

I get this error " The requested operation cannot be performed on a file with a user-mapped section open." what am I doing wrong?

Any help would be great

© Stack Overflow or respective owner

Related posts about wpf

Related posts about multithreading