CSharp笔记>>>多线程

几本资料C#并发编程经典实例

C#多线程学习exe    C#线程参考手册pdf

例子1:子线程更新UI

public void DoThreading()
        {
            ThreadStart starter = new ThreadStart(UpdateListBox);
            Thread t = new Thread(starter);
            t.Start();
            for (int i = 0; i < 4; i++)
            {
                listBox.Items.Add(new SkinListBoxItem("Message from UI"));
                listBox.Update();
            }
        }
        public string Message = "";
        public void WorkerUpdate(object sender, EventArgs e)
        {
            listBox.Items.Add(new SkinListBoxItem(Message));
            listBox.Update();
        }
        public void UpdateListBox()
        {
            for (int j = 0; j < 5; j++)
            {
                this.Message = "辅助线程的循环数" + j.ToString();
                this.listBox.Invoke(new EventHandler(WorkerUpdate));
                Thread.Sleep(4700);
            }
        }
原文地址:https://www.cnblogs.com/legion/p/6368004.html