蓝色港湾童装品牌:写操作xml文件,进程和线程同时写

来源:百度文库 编辑:九乡新闻网 时间:2024/04/28 14:40:07
            Mutex WriteMutex = new Mutex(false, "Write");
            WriteMutex.WaitOne();
            DateTime dttime = System.DateTime.Now;
            Response.Write(dttime);
            int i = 0;
            lock (this)
            {
                 while (System.DateTime.Now                 {
                     XmlDocument domtest = new XmlDocument();
                     domtest.Load(@"201012.xml");
                     XmlElement test = domtest.CreateElement("test");
                     i = i + 1;
                     test.SetAttribute("datetime", i.ToString());
                     domtest.DocumentElement.AppendChild(test);
                     domtest.Save(@"201012.xml");
                 }
            }
            WriteMutex.ReleaseMutex();            Response.Write("
"+Base.GetNowTime());
            return;