Click here to Skip to main content
15,868,016 members
Home / Discussions / C#
   

C#

 
AnswerRe: Unable to set program icon Pin
Christian Graus17-Sep-09 23:58
protectorChristian Graus17-Sep-09 23:58 
GeneralRe: Unable to set program icon [modified] Pin
yeah100018-Sep-09 0:29
yeah100018-Sep-09 0:29 
AnswerRe: Unable to set program icon Pin
PIEBALDconsult18-Sep-09 4:37
mvePIEBALDconsult18-Sep-09 4:37 
GeneralRe: Unable to set program icon Pin
yeah100020-Sep-09 20:15
yeah100020-Sep-09 20:15 
QuestionMultiThreading in c# Pin
nisharafic17-Sep-09 23:51
nisharafic17-Sep-09 23:51 
AnswerRe: MultiThreading in c# Pin
stancrm18-Sep-09 0:01
stancrm18-Sep-09 0:01 
AnswerRe: MultiThreading in c# Pin
Jacobb Michael18-Sep-09 1:01
Jacobb Michael18-Sep-09 1:01 
QuestionThread Performance Pin
Member 368144317-Sep-09 23:47
Member 368144317-Sep-09 23:47 
Hi All,

Im hoping someone can give me an idea on what I may be doing wrong (if anything). In my project I have a Combo Box which I populate from a SQL Database (using a Dataset and a for statement looping through each record). I have done it on form load and it works well however I decided to run it from a background thread so I become familiar with threads and for a few other reasons.

Anyway, i have done it using a Thread but I seem to have taken a very large performance hit. Without a thread, populating the combo box (on Form_Load) it takes about 1 second. With the Thread it takes about 6 seconds.

Im assuming since Im new with threads there is something obvious in my code that is wrong. Here is the relevant code in question:-

//Create Delegates for the Threads to Access The Forms UI
private delegate void UpdateComboBox(ComboBox cboName,string strItemToAdd);

Code in the Form_load Event
//Hide the Status Label
lblStatus.Visible = false;

//Start by Enabling the Loading Circle
//This is an indicator that the Background Thread is still running
//The Background thread is connecting to the database and populating the Combo Boxes
lblLoadingFormData.Text = "Loading Data";
lblLoadingFormData.Visible = true;
lcFormData.Active = true;

//Create the Thread which will Update the Combo Boxes
Thread thrPopulateComboBoxes = new Thread(this.PopulateComboBoxes);
thrPopulateComboBoxes.Start();

Code to Populate the Combo Box

private void PopulateComboBoxes()
{
//This Method will Populate the ComboBoxes on the Form
//Customers

ArrayList al = new ArrayList();

//Customers Combo Box
al = myDatabaseFunctions.PopulateComboBox("SELECT Name FROM tblCustomers ORDER BY Name ASC", "Name", "Customers");

foreach (string s in al)
{
this.Invoke(new UpdateComboBox(this.AddItemToComboBox),new object[] {cboCustomer,s.ToString()});
}
}

I know the issue is not with the Arraylist as this is the same sort of code I am using in a non thread and the performance is fine

Finally the code to add to Combo Box

private void AddItemToComboBox(ComboBox cboName, string strItem)
{
cboName.Items.Add(strItem);
}

Can any1 offer some thoughts as to why Im taking such a performance hit? Am I doing something wrong with the threads?

Thanks in advance,

Daniel.
AnswerRe: Thread Performance Pin
Nicholas Butler18-Sep-09 0:12
sitebuilderNicholas Butler18-Sep-09 0:12 
AnswerRe: Thread Performance Pin
Luc Pattyn18-Sep-09 2:08
sitebuilderLuc Pattyn18-Sep-09 2:08 
QuestionWeb Browser Event Hook - Problems Pin
Jacobb Michael17-Sep-09 23:31
Jacobb Michael17-Sep-09 23:31 
AnswerRe: Web Browser Event Hook - Problems Pin
omizyurko6-Jun-11 2:21
omizyurko6-Jun-11 2:21 
AnswerRe: Web Browser Event Hook - Problems Pin
j to the 4n8-Nov-13 0:05
j to the 4n8-Nov-13 0:05 
QuestionHelp making threads work in C# similar to Java Pin
Cruces17-Sep-09 23:17
Cruces17-Sep-09 23:17 
AnswerRe: Help making threads work in C# similar to Java Pin
Nicholas Butler18-Sep-09 0:19
sitebuilderNicholas Butler18-Sep-09 0:19 
GeneralRe: Help making threads work in C# similar to Java Pin
Cruces18-Sep-09 2:14
Cruces18-Sep-09 2:14 
GeneralRe: Help making threads work in C# similar to Java Pin
Nicholas Butler18-Sep-09 4:17
sitebuilderNicholas Butler18-Sep-09 4:17 
GeneralRe: Help making threads work in C# similar to Java Pin
Cruces18-Sep-09 4:33
Cruces18-Sep-09 4:33 
QuestionHow can we set formats of excel sheet Pin
Gunjan pandey17-Sep-09 23:16
Gunjan pandey17-Sep-09 23:16 
QuestionDraw Controls in Layers Pin
softwarejaeger17-Sep-09 22:52
softwarejaeger17-Sep-09 22:52 
QuestionDatagridview refreshes automatically reflecting changes in database? Pin
LordZoster17-Sep-09 21:54
LordZoster17-Sep-09 21:54 
AnswerRe: Datagridview refreshes automatically reflecting changes in database? Pin
Christian Graus17-Sep-09 21:56
protectorChristian Graus17-Sep-09 21:56 
AnswerRe: Datagridview refreshes automatically reflecting changes in database? Pin
Tamer Oz17-Sep-09 22:05
Tamer Oz17-Sep-09 22:05 
GeneralRe: Datagridview refreshes automatically reflecting changes in database? Pin
Christian Graus17-Sep-09 22:07
protectorChristian Graus17-Sep-09 22:07 
GeneralRe: Datagridview refreshes automatically reflecting changes in database? Pin
Tamer Oz17-Sep-09 22:15
Tamer Oz17-Sep-09 22:15 

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.