Click here to Skip to main content
15,561,011 members
Home / Discussions / C#
   

C#

 
AnswerRe: Unable to set program icon Pin
Christian Graus18-Sep-09 0:58
mveChristian Graus18-Sep-09 0:58 
GeneralRe: Unable to set program icon [modified] Pin
yeah100018-Sep-09 1:29
yeah100018-Sep-09 1:29 
AnswerRe: Unable to set program icon Pin
PIEBALDconsult18-Sep-09 5:37
professionalPIEBALDconsult18-Sep-09 5:37 
GeneralRe: Unable to set program icon Pin
yeah100020-Sep-09 21:15
yeah100020-Sep-09 21:15 
QuestionMultiThreading in c# Pin
nisharafic18-Sep-09 0:51
nisharafic18-Sep-09 0:51 
AnswerRe: MultiThreading in c# Pin
stancrm18-Sep-09 1:01
stancrm18-Sep-09 1:01 
AnswerRe: MultiThreading in c# Pin
Jacobb Michael18-Sep-09 2:01
Jacobb Michael18-Sep-09 2:01 
QuestionThread Performance Pin
Member 368144318-Sep-09 0:47
Member 368144318-Sep-09 0: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 1:12
sitebuilderNicholas Butler18-Sep-09 1:12 
AnswerRe: Thread Performance Pin
Luc Pattyn18-Sep-09 3:08
sitebuilderLuc Pattyn18-Sep-09 3:08 
QuestionWeb Browser Event Hook - Problems Pin
Jacobb Michael18-Sep-09 0:31
Jacobb Michael18-Sep-09 0:31 
AnswerRe: Web Browser Event Hook - Problems Pin
omizyurko6-Jun-11 3:21
omizyurko6-Jun-11 3:21 
AnswerRe: Web Browser Event Hook - Problems Pin
j to the 4n8-Nov-13 1:05
j to the 4n8-Nov-13 1:05 
QuestionHelp making threads work in C# similar to Java Pin
Cruces18-Sep-09 0:17
Cruces18-Sep-09 0:17 
AnswerRe: Help making threads work in C# similar to Java Pin
Nicholas Butler18-Sep-09 1:19
sitebuilderNicholas Butler18-Sep-09 1:19 
GeneralRe: Help making threads work in C# similar to Java Pin
Cruces18-Sep-09 3:14
Cruces18-Sep-09 3:14 
GeneralRe: Help making threads work in C# similar to Java Pin
Nicholas Butler18-Sep-09 5:17
sitebuilderNicholas Butler18-Sep-09 5:17 
GeneralRe: Help making threads work in C# similar to Java Pin
Cruces18-Sep-09 5:33
Cruces18-Sep-09 5:33 
QuestionHow can we set formats of excel sheet Pin
Gunjan pandey18-Sep-09 0:16
Gunjan pandey18-Sep-09 0:16 
QuestionDraw Controls in Layers Pin
softwarejaeger17-Sep-09 23:52
softwarejaeger17-Sep-09 23:52 
QuestionDatagridview refreshes automatically reflecting changes in database? Pin
LordZoster17-Sep-09 22:54
LordZoster17-Sep-09 22:54 
AnswerRe: Datagridview refreshes automatically reflecting changes in database? Pin
Christian Graus17-Sep-09 22:56
mveChristian Graus17-Sep-09 22:56 
AnswerRe: Datagridview refreshes automatically reflecting changes in database? Pin
Tamer Oz17-Sep-09 23:05
Tamer Oz17-Sep-09 23:05 
GeneralRe: Datagridview refreshes automatically reflecting changes in database? Pin
Christian Graus17-Sep-09 23:07
mveChristian Graus17-Sep-09 23:07 
GeneralRe: Datagridview refreshes automatically reflecting changes in database? Pin
Tamer Oz17-Sep-09 23:15
Tamer Oz17-Sep-09 23: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.