ListBox update

  • Thread starter Thread starter Gavaskar
  • Start date Start date
G

Gavaskar

Hello

I've got a listBox on a Windows form in which I add data to it ,as needed,
or so I think.

Basically I'm cycling oversome data and if I find some matches, I call my
helper function AddtoList(str)

public void somefunc()
{
AddToList("sometexttodisplay");
}

public void AddToList(String s)
{
string sOut = datetime.TimeOfDat.ToString() + s ;
listBox1.Add(sOut);

}

Now the the gets displayed, but after the program has stopped running. How
do I have the listbox update when the line listBox1.Add(sOut); is actually
excuted?
 
Hello

I used the listBox1.Items.Add(sOut); listBox1.Update(); method

At first it seems to work, but I noticed that as I'm adding more strings to
the listbox, I'm not able to use the scroll bar, to scroll down the list,
until I've finished adding data.

Is that something, that putting the list box into a separate thread would
take care of?
 
Ok, Thanks

In your example you start the method RunThread(); in a new thread.

Now what if I wanted to pass data into that method? So the method signature
would be
void RunThread(string s) {.....}

Would I be able to do something like
void StartProcessing()
{
new Thread(RunThread(string s)).Start();
}
 
Back
Top