日期:2014-05-17  浏览次数:21225 次

C#中listbox删除出现未将对象引用设置到对象实例
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Threading;

namespace Error
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        public void Ad(string x)
        {
            if (listBox1.Items.Count > 19)
            {
                if(!string.IsNullOrEmpty(listBox1.Items[listBox1.Items.Count - 1].ToString()))
                {
                    listBox1.Items.RemoveAt(listBox1.Items.Count - 1);
                }
               
            }
            listBox1.Items.Insert(0, x);
        }
        private void button1_Click(object sender, EventArgs e)
        {
            Thread A1;
            Thread A2;
            Thread A3;
            Thread A4;
            Control.CheckForIllegalCrossThreadCalls = false;
            A1 = new Thread(new ThreadStart(AutoPic1));
            A1.Start();
            Control.CheckForIllegalCrossThreadCalls = false;
            A2 = new Thread(new ThreadStart(AutoPic2));
            A2.Start();
            Control.CheckForIllegalCrossThreadCalls = false;
            A3 = new Thread(new ThreadStart(AutoPic3));
            A3.Start();
            Control.CheckForIllegalCrossThreadCalls = false;