关于委托,调用的奇怪问题

如下:lbxLog是一个用来显示信息的listbox,下面的委托和方法也是定义在主线程。但是在主线程中调用和在其他线程中调用,居然互不影响:主线程中调用后Items.Count能增加,但是其他线程中调用,却是另外的一个Items.Count值,两个线程都是自己加自己的。其中主线程增加的Item 可以显示出来,其他线程的却不能显示。

        public delegate void ListBoxCallback(string str);
        public void SetListBox(string str)
        {
            try
            {
                if (lbxLog.InvokeRequired == true)
                {
                    ListBoxCallback d = new ListBoxCallback(SetListBox);
                    lbxLog.Invoke(d, str);
                }
                else
                {
                    this.lbxLog.Items.Insert(lbxItemCount, str);
                    lbxItemCount++;
                }
            }
            catch(Exception ex)
            {
                log.Error("屏幕信息显示出错:", ex);
            }
        }

 

怎样才能让所有线程调用后增加的Item全显示出来?

慕哥6287543
浏览 443回答 4
4回答

杨__羊羊

谢谢,受到启发
打开App,查看更多内容
随时随地看视频慕课网APP