I was trying that InvokeRequired stuff but it kept throwing errors...
perhaps I didn't write it right, but eventually I just forced an
Invoke regardless, and that seems to work alright. Of course, that
moves the encapsulation outside the method, which isn't nice, but oh
well. I'll give this a shot again. Thanks :)

On Aug 20, 2:22 am, sallushan <[EMAIL PROTECTED]> wrote:
> Check the "InvokeRequired" property and then use "Invoke()" method, as
> described in documentation (you can check the msdn)
>
>  private void Download()
>         {
>            if (listView1.InvokeRequired)
>           {
>               listView1.Invoke(new MethodInvoker(Download));
>           }
>           else
>           {
>             while (true)
>             {
>                 if (listView1.Items.Count > 0)
>                 {
>                     listView1.Items.RemoveAt(0);
>                 }
>             }
>           }
>         }
>
> I think for this purpose, "BackgroundWorker" is a better choice.
>
> Regards
> Arsalan Tamiz
>
> On Aug 20, 3:50 am, Mark <[EMAIL PROTECTED]> wrote:
>
> > I'm making a Windows Forms Application. It contains a ListView, a
> > TextBox and a Button. The user can type some stuff in the TextBox,
> > click the Button, and it will be added to the ListView. I want to
> > process the items in the ListView and then pop them off list, using a
> > separate thread, so that the program doesn't hang and the user can add
> > more items while it's running. With what I have right now, I can't
> > remove items from the list from a different thread. I understand why
> > this causes problems, but I'm not sure how to fix it. I've tried
> > following a few tutorials to use delegates, but I can't seem to get it
> > to work. Here's what I've got right now:
>
> > using System;
> > using System.Collections.Generic;
> > using System.ComponentModel;
> > using System.Data;
> > using System.Drawing;
> > using System.Text;
> > using System.Windows.Forms;
> > using System.Text.RegularExpressions;
> > using System.Threading;
>
> > namespace ImageDownloader
> > {
> >     public partial class Form1 : Form
> >     {
> >         public Form1()
> >         {
> >             InitializeComponent();
> >         }
>
> >         private void Download()
> >         {
> >             while (true)
> >             {
> >                 if (listView1.Items.Count > 0)
> >                 {
> >                     listView1.Items.RemoveAt(0);
> >                 }
> >             }
> >         }
>
> >         private void button1_Click(object sender, EventArgs e)
> >         {
> >            listView1.Items.Add(textBox1.Text);
> >            textBox1.Text = "";
> >         }
>
> >         private void Form1_Load(object sender, EventArgs e)
> >         {
> >             Thread t = new Thread(new ThreadStart(Download));
> >             t.Start();
> >         }
> >     }
>
> > }
>
> > This theoretically should just remove all the items from the list as
> > soon as they are added, one by one. Obviously I'll do some processing
> > on each item first, but I need to get this working before I get into
> > that :)
>
> > Thanks for any help.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web 
Services,.NET Remoting" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://cm.megasolutions.net/forums/default.aspx
-~----------~----~----~----~------~----~------~--~---

Reply via email to