Delay using a Listbox problem

  • Thread starter Thread starter Steven Blair
  • Start date Start date
S

Steven Blair

Hi,

I have a function made up of several processes. After each process I
want to write the status of the provess out to a Listbox:

void MyFunc()
{
if( DoSomething1() )
{
lsOutput.Items.Add("Success 1");
}

if( DoSomething2() )
{
lsOutput.Items.Add("Success 2");
}

//And so on
}

The problem is, none of the details are displayed to the Listbox until
all the processing is finished.

Can anyone help me out?

Regards,

Steven
 
Hi, Steven

if process runs in same thread, for example, UI, you have to allow message
pump to route appropriate messages including Paint to corresponding
controls. This means that somewhere in the process code you must have
DoEvents call. Even this won't guarantee timely updates. It is generally
recommended to perform long running processes in separate threads or
asynchronously to keep UI thread responsive.

You might want to check for example
http://msdn.microsoft.com/msdnmag/issues/03/02/Multithreading for
recommended approaches.

HTH
Alex
 
Back
Top