Click here to Skip to main content
15,905,776 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi
i am using a listbox in c# winform.
i wanna to display all rows i add in listbox in moment the event button click is executed.
the event of button click need around 8 - 10 sec to finish the work
and add around (300 +-30) rows i get the data from 3 webservice.
i get from first service and i add in listbox, then i get from sec service add to listbox and last service i add to listbox.

know i wanna show the rows in time they are add real time. not to wait till the the event of button click is finished.
can some one suggest me how to do it?

sorry for my bad english.
Posted

If you have some slow operation but want to keep UI responsive at all times, you certainly need to do such operations in a separate, non-UI thread.

However, how to update the UI thread with new data or anything, from a non-UI thread. The trouble is: you cannot call anything related to UI from non-UI thread.

Instead, you need to use the method Invoke or BeginInvoke of System.Windows.Threading.Dispatcher (for both Forms or WPF) or System.Windows.Forms.Control (Forms only).

You will find detailed explanation of how it works and code samples in my past answers:
Control.Invoke() vs. Control.BeginInvoke()[^],
Problem with Treeview Scanner And MD5[^].

See also more references on threading:
How to get a keydown event to operate on a different thread in vb.net[^],
Control events not firing after enable disable + multithreading[^].

—SA
 
Share this answer
 
HI,

You can set the auto refresh like thing in your control. This will be refreshed periodically automatically and your data will be refreshed. Refer the following link:

Refresh a windows form, even when not the active window

Set the time for refreshment of the data and get the latest data from the database. HOpe this will resolve your problem.

Thanks
 
Share this answer
 
Comments
nika2008 6-Aug-13 9:06am    
thnx alot +5
[no name] 6-Aug-13 9:07am    
You are welcome dear... please accept the solution too.
nika2008 6-Aug-13 9:08am    
:) done
[no name] 6-Aug-13 9:22am    
Thanks dear. All d best with coding... Any help feel free to ping me...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900