multithreading - C# Delegate confusion and lack of knowledge -


i'm confused delegates, mind going eat itself.

i want connect 2 different threads stuff one-another. obviously, "cross-thread calls unsafe" exceptions on place, demanding provide delegates instead. have read countless tutorials, documentations, examples, , die little more inside each example, because try it, does not work.

here's set-up in simplified, code-free way:

i have 2 threads

.

thread1 has class display_with_richtextbox

that class has rich_text_box editing.

that class has method int write_to_textbox_and_return_feedback(string text)

.

thread2 has class some_control_panel

that class has text_box_of_doom text in it

that class has button_of_magic call method other class add textbox's text richtextbox. upon execution of method, method return me int new total size of rich text box's text.

.

my problem is, can't figure out how make structure neatest.

  1. do explicitly manipulate controls via delegate or something, making thread2 upgrade thread1, making easy take in/out of code
  2. do call method editing me, make thread1 class dependent on thread2 class?

and how build delegate. every time try anything, anywhere, code complains delegates can used things static, highly impractical i'm aiming create. can workaround making variables in thread1, edit them thread2, , let thread1 figure out variables, therefore passing interactions thread2>thread1. makes thread1 code untidy , un-neat wanna cry.

is there way of calling functions thread2 -> thread1 that's neat , doesn't involve variables , custom thread-locking-code-of-doom manage variables , stuff?

i hope can understood mean.

.

i want have thread1 > class1 > rich text box

that can edit use of thread2 > class2 > button don't edit -anything- in thread1 > class1

i'm aiming make thread2 stuff complete addon program, making dependency one-way (thread2 depends on thread1, without thread1 expecting it)

if it's impossible make thread1 oblivious thread2, can at-least make thread1 involvement minimal?

.

edit: if delegates , other related stuff not looking for, looking for, if want seperate pieces of code run in own threads, independent of eachother, mess eachother achieve greater goal; such editing eachother in way;, 1. develop "class program" run on own, later make addon 2. "class addon" messes program wants, without needing go , edit program code allow communication between 2 programs. there programming language can achieve this, if c# cannot?

this use on form app hop between threads , change ui controls

program.mainform.invoke((methodinvoker)delegate {      //do changes here    });' 

Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -