public class A { private int ticket; public int Ticket { get { lock (ticket.ToString()) return ticket; } set { lock (ticket.ToString()) ticket = value; } } } A a=new A(); private void Test() { while (a.Ticket> 0) { MessageBox.Show(a.Ticket.ToString()); a.Ticket--; } } private void button3_Click(object sender, EventArgs e) { new Thread(new ThreadStart(Test)).Start(); new Thread(new ThreadStart(Test)).Start(); }
把问题描述清楚好不好
同意楼上
提供一个思路:
1、一个辅助线程专门处理排队 (注意队列要保持线程安全即,插入,删除等等要lock)
2、一个System.Threading.timer定时检查是否有票,有票就循环排队队列给票
贴一个出来看看