views:

40

answers:

0

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();
    }