如何在多线程中应用SpiderStudio生成的DLL2014-06-10 cnblogs Ivan Zou代码:
using System;using System.Collections.Generic;using System.Linq;using System.Text;using www.utilities_online.info;using System.Threading;using System.Threading.Tasks;namespace ConsoleApplication4{class Program{static void Main(string[] args){Thread t = new Thread(new ThreadStart(() =>{var xml = "<person><name>Mike</name><age>30</age></person>";var json = new XmlJsonConverter().Xml2Json(xml);Console.WriteLine(json.Replace("
", ""));}));t.SetApartmentState(ApartmentState.STA); //一定要指定线程在单线程模式下运行t.Start();Console.WriteLine("线程已开始...");while (t.ThreadState != ThreadState.Stopped){Thread.Sleep(1000);}Console.WriteLine("线程已停止.");}}}效果: