c# - How to assign multiple threads to similar controls on windows form? -


how assign different threads more 1 control on windows form using c# .net 3.5? want 3 textboxes each connected thread running same function, count number of odd numbers in array.

ideally usage like:

//count number of odd numbers in array , when  //done set textbox value void assigntasktotexbox( textbox textbox, int[] array); 

the code can run in thread assigned textbox have signature like:

int getcount(int[] array);  //usage: asssigntasktotexbox( textbox1, array1); asssigntasktotexbox( textbox2, array2); 

after each call of assigntasktotextbox task assigned asynchronously textbox. go of count , set text when done i.e. program go of other things , when tasks complete textboxes updated in background. new threading , pointers how proceed.

it doesn't make sense assign thread control. of ui runs on single thread, called "main" or "ui" thread.

and there's not point in running same code multiple times, if it's happening "simultaneously" on multiple threads. sounds me need calculate result once , display in multiple textboxes. requires 1 background thread.

either way, don't over-complicate things. use backgroundworker component make spinning off computational tasks background threads easier on yourself. drop 1 on form, add handler dowork event (where computation), , handler runworkercompleted (where display results of computation).

if have trouble following that, there's great example of how make tick @ bottom of linked documentation. modify needs.


Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -