using System; using System.Collections; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Threading; namespace ThreadApplication { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { try { label1.Text = Thread.CurrentThread.Name; string[] fruits; fruits = new string[5]; fruits[0] = "Banana"; fruits[1] = "Grape"; fruits[2] = "Apple"; fruits[3] = "Orange"; fruits[4] = "Pappaya"; foreach (var fruit in fruits) { listBox1.Items.Add(fruit); listBox1.Refresh(); } var list = new ArrayList(); list.AddRange(listBox1.Items); Thread objNewThread = new Thread(new ParameterizedThreadStart(objAddFruits.ConsumerJob)); objNewThread.Start(list); Thread.Sleep(1000); MessageBox.Show("" + Thread.CurrentThread.Priority); } catch (Exception ex) { MessageBox.Show("" + ex.Message); throw; } } private void button2_Click(object sender, EventArgs e) { //new ConsumerJobClass().ConsumerJob(); } } public class ConsumerJobClass :Form1 { public void ConsumerJob(object list) { var frm=new Form1(); ArrayList arrayList=(ArrayList)list; foreach (var item in arrayList) { if (!frm.IsHandleCreated) frm.CreateControl(); frm.listBox2.Invoke((MethodInvoker)delegate() { frm.listBox2.Items.Add(item); }); // I got Error here listBox2.Refresh(); this.Invoke(new Action(() => listBox1.Items.Remove(item))); listBox1.Items.Remove(item); listBox1.Refresh(); } } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)