Click here to Skip to main content
15,908,843 members
Home / Discussions / C#
   

C#

 
GeneralRe: Please contribute to developing a perfect ComboBox with item tooltips and enable/disable capability Pin
arnold_w20-Oct-08 5:27
arnold_w20-Oct-08 5:27 
GeneralRe: Please contribute to developing a perfect ComboBox with item tooltips and enable/disable capability Pin
Dan Neely20-Oct-08 6:37
Dan Neely20-Oct-08 6:37 
Questionc# winform freeze Pin
arkiboys20-Oct-08 2:13
arkiboys20-Oct-08 2:13 
AnswerRe: c# winform freeze Pin
elektrowolf20-Oct-08 3:12
elektrowolf20-Oct-08 3:12 
GeneralRe: c# winform freeze Pin
Simon P Stevens20-Oct-08 3:17
Simon P Stevens20-Oct-08 3:17 
AnswerRe: c# winform freeze Pin
Ashfield20-Oct-08 3:13
Ashfield20-Oct-08 3:13 
GeneralRe: c# winform freeze Pin
arkiboys20-Oct-08 3:16
arkiboys20-Oct-08 3:16 
AnswerRe: c# winform freeze Pin
Simon P Stevens20-Oct-08 3:14
Simon P Stevens20-Oct-08 3:14 
arkiboys wrote:
Is this to do with threads?


Kind of.

You are obviously doing a lot of stuff in the button click event handler.

A standard winforms app has a GUI thread which does all the form drawing and event processing. When you click the button, that thread triggers the event handler. If you then do a lot of time consuming work in the event handler, the GUI thread is tied up so can't do any other work, like redrawing the list box or processing other button clicks. What you need to do is do any long running tasks on a background thread. The easiest way to do this is with a BackgroundWorker[^]

One of the quirks of winforms is that only the GUI thread can actually update any controls. This means that you will need to do your complex calculations on the background thread, but switch back to the GUI thread to add the items to the list box. You use the Invoke method on the form to call code on the GUI thread.
if(this.InvokeRequired)
   {
      dosomethingdelegate dsd = new dosomethingdelegate(dosomethingmethod);
      this.Invoke(dsd, anyParametersGoHere);
   }


To do this, I would group them up into blocks, do the processing on the background thread, then call a method to add several at a time using the ListBox.Items.AddRange method on the GUI thread. This will also reduce the number of repaints of the list box that the app needs to do, so will improve it's performance.

Simon

GeneralRe: c# winform freeze Pin
N a v a n e e t h20-Oct-08 3:37
N a v a n e e t h20-Oct-08 3:37 
GeneralRe: c# winform freeze Pin
Simon P Stevens20-Oct-08 3:42
Simon P Stevens20-Oct-08 3:42 
Questionview data on gridview Pin
mohammadcom20-Oct-08 1:08
mohammadcom20-Oct-08 1:08 
AnswerRe: view data on gridview Pin
Ashfield20-Oct-08 1:18
Ashfield20-Oct-08 1:18 
AnswerRe: view data on gridview Pin
nelsonpaixao20-Oct-08 12:55
nelsonpaixao20-Oct-08 12:55 
Questionwhat is .pfx file Pin
wasimsharp19-Oct-08 23:49
wasimsharp19-Oct-08 23:49 
AnswerRe: what is .pfx file Pin
Pete O'Hanlon20-Oct-08 0:12
mvePete O'Hanlon20-Oct-08 0:12 
QuestionMerge List in .NET Pin
papy-boom19-Oct-08 23:37
papy-boom19-Oct-08 23:37 
AnswerRe: Merge List in .NET Pin
Simon P Stevens19-Oct-08 23:45
Simon P Stevens19-Oct-08 23:45 
AnswerRe: Merge List in .NET Pin
Guffa20-Oct-08 1:21
Guffa20-Oct-08 1:21 
QuestionListView Pin
boiDev19-Oct-08 23:25
boiDev19-Oct-08 23:25 
AnswerRe: ListView Pin
Shyam Bharath19-Oct-08 23:31
Shyam Bharath19-Oct-08 23:31 
QuestionHow to get RTC(Real time clock) time using c#? Pin
lovnin19-Oct-08 23:08
lovnin19-Oct-08 23:08 
AnswerRe: How to get RTC(Real time clock) time using c#? Pin
Simon P Stevens19-Oct-08 23:10
Simon P Stevens19-Oct-08 23:10 
GeneralRe: How to get RTC(Real time clock) time using c#? Pin
lovnin19-Oct-08 23:16
lovnin19-Oct-08 23:16 
GeneralRe: How to get RTC(Real time clock) time using c#? Pin
Simon P Stevens19-Oct-08 23:34
Simon P Stevens19-Oct-08 23:34 
QuestionRemove/Uninstall Applications Pin
Starzfighter19-Oct-08 22:54
Starzfighter19-Oct-08 22:54 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.