日期:2014-05-17 浏览次数:20782 次
public class StringQueueTest
{
private int cnt=0;
private Queue<string> strings=new Queue<string>();
public StringQueueTest()
{
Thread thread1=new Thread(new ThreadStart(Start1));
Thread thread2=new Thread(new ThreadStart(Start2));
thread1.Start();
thread2.Start();
}
private void Start1()
{
while (true)
{
string s=(cnt++).ToString();
Console.WriteLine(s);
strings.Enqueue(s);
Thread.Sleep(1000);
}
}
private void Start2()
{
while (true)
{
while (strings.Count>0)
{
Console.WriteLine(strings.Dequeue());
}
Thread.Sleep(100);
}
}
}
backgroundworker就可搞定!
private static StringBuilder strs = new StringBuilder();
private static BackgroundWorker backgroundWorker;
static void Main(string[] args)
{
backgroundWorker = new BackgroundWorker();
backgroundWorker.DoWork += TransString;
backgroundWorker.RunWorkerCompleted += DisplayString;
//处理string
for (int i = 0; i < 10; i++)
{
string str = Console.ReadLine();
&nbs