DataTable.WriteXml on background thread

Posted by Sheraz KHan on Stack Overflow See other posts from Stack Overflow or by Sheraz KHan
Published on 2010-04-23T15:49:10Z Indexed on 2010/04/23 15:53 UTC
Read the original article Hit count: 386

Filed under:
|

I am trying to serealize DataTables in a background thread and it's failing. Any idea

    [Test]
    public void Async_Writing_DataTables()
    {
        string path = @"C:\Temp\SerialzeData";
        if (!Directory.Exists(path))
        {
            Directory.CreateDirectory(path);
        }
        Assert.IsTrue(Directory.Exists(path));

        Thread thread1 = new Thread(new ThreadStart(delegate
                                                        {
                                                            object lockObject = new object();
                                                            for (int index = 0; index < 10; index++)
                                                            {
                                                                lock (lockObject)
                                                                {
                                                                    DataTable table = new DataTable("test");
                                                                    table.WriteXml(Path.Combine(path, table.TableName + index + ".xml"));
                                                                }
                                                            }
                                                        }));


        thread1.Start();
    }

© Stack Overflow or respective owner

Related posts about multithreading

Related posts about c#