我不太清楚,你为什么会设计成这样,多线程的处理非常麻烦,建议你还是重新考虑一下设计.如果确实要用,你这块有三个问题需要注意,listview必须由

解决方案 »

  1.   

    我不太清楚,你为什么会设计成这样,多线程的处理非常麻烦,建议你还是重新考虑一下设计.如果确实要用,你这块有三个问题需要注意,
    1.listview必须由UI线程处理,因此会有IVOKE切换的问题;
    2.多线程需对同一个listview处理,有一个锁或者队列的问题.
    3.可能还有一个线程的同步和通信问题.我想如果搞清这三点,至于实现应该是非常简单的事,不需要看什么事例代码.
      

  2.   

    主线程:
    第一步:定义委托delegate
    private delegate void setConn(string strConn);
    private setConn mySetConn = null;
    第二步:定义一个方法
    private void DispText(string strConn)
    {
        textBox1.Text = strConn;
    }
    第三步:初始化委托
    mySetConn = new setConn(this.DispText);
    第四步:在工作线程中
    this.Invoke(mySetConn, "把我显示在textBox1中,谢谢!");
      

  3.   

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using System.Threading;namespace WindowsApplication1
    {
        public partial class Form1 : Form
        {
            Thread newThread;
            delegate void myDelegate(string _strFrame);
            myDelegate mydelegate = null;        public Form1()
            {
                InitializeComponent();
            }        private void button1_Click(object sender, EventArgs e)
            {
                mydelegate = new myDelegate(ShowText);
                this.textBox1.Text = "begin";
                newThread = new Thread(new ThreadStart(Thread_proc));
                newThread.Start();
            }
            private void Thread_proc()
            {
                Random a = new Random();
                int b = a.Next(100);
                //this.textBox1.Text = b.ToString();
                ShowText(b.ToString());
            }        private void textBox1_TextChanged(object sender, EventArgs e)
            {
                MessageBox.Show("Text changed");
            }        private void ShowText(string strText)
            {
                if (this.textBox1.InvokeRequired)
                {
                    mydelegate = new myDelegate(ShowText);
                    this.Invoke(mydelegate, new object[] { strText });
                }
                else
                {
                    if (textBox1.TextLength < 1000)
                        textBox1.Text += strText;
                    else
                        textBox1.Text = strText;
                }
            }
        }
    }
      

  4.   

    以上例子,线程里控制ui里的textbox.2005下调试通过
      

  5.   

    上面几个全部不对,你们写的比我要求的简单多了!
    ristona(一箭) 说的很对,确实是这几个要求,但是下面几位没有一个达到要求的,你们写的要比我要求的简单多了
      

  6.   

    http://blog.csdn.net/chendazhi/archive/2006/05/09/715064.aspx