I have a silly question which prevents me to proceed with my project.
My project involves multi-threading(foreground threads), so i would like to have all my threads kept in a different .cs file than Form1.cs.
Is this a good call or i should write
all my methods in the Form.cs? All the examples found on the net have the methods in the same class.
The problem that I am facing is: how to update my controls in the Form1.
If i had put my methods in the Form class it would be easy, i would have used:
if(this.InvokeRequired)
this.Invoke((Action)(() => richTextBox.Text += (line + Environment.NewLine)));
but updating that control from another class it gives me a headache, knowing that i might miss something rather simple.
This statement is somewhat inaccurate as threads simply have execution contexts, which can be code from your Form1.cs or any other class file. However, I always prefer to only have form logic/manipulation code in my forms. Any other code should be elsewhere. With that, your other classes should NOT know about your form – that produces unnecessary coupling.
Use events or callbacks to invoke responses you want of your form. Your form should then contain the code that invokes your UI manipulation code to run on the main UI thread.