Click here to Skip to main content
15,914,594 members
Home / Discussions / C#
   

C#

 
GeneralRe: OleDB Insert into MS Access Pin
Vodstok1-Mar-05 10:26
Vodstok1-Mar-05 10:26 
GeneralRe: OleDB Insert into MS Access Pin
Anonymous1-Mar-05 10:42
Anonymous1-Mar-05 10:42 
GeneralRe: OleDB Insert into MS Access Pin
Troske1-Mar-05 12:29
Troske1-Mar-05 12:29 
GeneralProcess.HasExited problems Pin
3Dizard1-Mar-05 9:44
3Dizard1-Mar-05 9:44 
GeneralRe: Process.HasExited problems Pin
Dave Kreskowiak1-Mar-05 10:14
mveDave Kreskowiak1-Mar-05 10:14 
GeneralRe: Process.HasExited problems Pin
3Dizard2-Mar-05 23:10
3Dizard2-Mar-05 23:10 
GeneralRe: Process.HasExited problems Pin
3Dizard3-Mar-05 0:14
3Dizard3-Mar-05 0:14 
GeneralBasic Thread Questions Pin
GhostsOfOrion1-Mar-05 8:29
GhostsOfOrion1-Mar-05 8:29 
Greetings,

This is my first post to the forum. I am a relatively new programmer and hope that my questions aren't too simple or obvious for someone at my level. I think I am getting the hang of it but am wrestling with Invoking back to the Main Thread. I have some fundamental questions that would help me understand the basics. I trust someone here will have the right answers.

From what I understand so far each Form runs in its own thread and each of its controls run on their own threads. I wish that we were in person so that you could stop me right here if I'm wrong but I will continue with my questions based on that premise which leads me to my first question.

1. When the Application.Run() method (in the main entry point for the application.) runs the Form passed to it, is there now 2 threads running? The App thread and the Form's thread? Or does the Form's thread become the MAIN THREAD?

Either way there is a Main Thread. So, when other threads are run from the main thread they need to Invoke() or BeginInvoke() back to the main thread, as they need to change variables in the app's main thread or else the change only seems to occur in the context of the thread making the changes. Now, if this is true then my next question is this:

2. Is it normal to have a large amount of EventHandlers in the main thread (main form?) for the other threads to invoke back to?

Let's say I have 40 classes that need to call back to the main thread with invoke. Is it normal to pass the main thread object into their constructor so that they can reference the main object? Something like this:

Form2 frm2 = new Form2(this);

This is how I have been doing it and it just seems messy. I mean, it just doesn't seem like I'm doing this right. If this is normal (or good coding practice) then my next question is this... and it is real basic so please don't laugh! lol

3. When you pass an object into another (or a method I would presume) does that object get copied into a new area in memory?

I know that there is a ref keyword that only sends a reference to the same memory. If this is the case why don't I see the ref keyword all over the place? It seems like it is rarely used. Even in places where it seems like it should have been used it isn't. Is there a reason for this? With that in mind my next question is this:

4. If passing my main-thread-form into each of my 40 class's constructor (as shown above) does that mean that I now have 41 main-thread-form-objects in memory? If so, wouldn't it be better to:
Form2 frm2 = new Form2(ref this);

...and use the reference to invoke off of?

I know these are fundamental concepts and I have been trying to get answers to this but none of the books I have give me the straight-dope on the practical usage. And I ask the book a question and it just sits there!

5. If passing the main-thread-form into every other class that needs to talk with it isn't the right way to do this then what is?

Let's say I have 500 classes that need to either change vars in the main class or invoke back to the main-thread-form. It seems ridicules to be passing it into the constructor like this. Especially if each one has a separate copy of the main-object.

6. Is the answer some kind of static object which contains the instance of the object? Thus avoiding all the copying and passing?

I haven't done that yet as it doesn't make sense either.

If passing the main-thread-form around like this is, indeed, the way to construct an app I would be totally cool with that and continue on my way. But it doesn't seem right and I hope you can point me in the right direction.


EB
GeneralRe: Basic Thread Questions Pin
S. Senthil Kumar1-Mar-05 8:58
S. Senthil Kumar1-Mar-05 8:58 
GeneralRe: Basic Thread Questions (LONG) Pin
GhostsOfOrion1-Mar-05 16:00
GhostsOfOrion1-Mar-05 16:00 
GeneralRe: Basic Thread Questions (LONG) Pin
S. Senthil Kumar1-Mar-05 17:04
S. Senthil Kumar1-Mar-05 17:04 
GeneralRe: Basic Thread Questions (LONG) Pin
GhostsOfOrion2-Mar-05 4:17
GhostsOfOrion2-Mar-05 4:17 
GeneralInherited Forms in Compact Framework Pin
Tristan Rhodes1-Mar-05 7:59
Tristan Rhodes1-Mar-05 7:59 
GeneralOverriding Text in UserControl :confused: Pin
_eulogy_1-Mar-05 7:56
_eulogy_1-Mar-05 7:56 
GeneralRe: Overriding Text in UserControl :confused: Pin
spif20011-Mar-05 20:20
spif20011-Mar-05 20:20 
GeneralRe: Overriding Text in UserControl :confused: Pin
_eulogy_2-Mar-05 0:33
_eulogy_2-Mar-05 0:33 
GeneralForm Designer for Lightweight Framework Pin
Tristan Rhodes1-Mar-05 7:32
Tristan Rhodes1-Mar-05 7:32 
Generalupdating already opened window/form Pin
Adnan Siddiqi1-Mar-05 7:09
Adnan Siddiqi1-Mar-05 7:09 
GeneralExporting Crystal Reports To PDF Errors Pin
Khang Nguyen1-Mar-05 7:03
Khang Nguyen1-Mar-05 7:03 
GeneralRe: Exporting Crystal Reports To PDF Errors Pin
Raganar1-Mar-05 7:59
Raganar1-Mar-05 7:59 
GeneralRe: Exporting Crystal Reports To PDF Errors Pin
Khang Nguyen1-Mar-05 8:24
Khang Nguyen1-Mar-05 8:24 
GeneralAttributes property Pin
MyThread1-Mar-05 6:19
MyThread1-Mar-05 6:19 
GeneralRe: Attributes property Pin
Robert Rohde1-Mar-05 6:51
Robert Rohde1-Mar-05 6:51 
GeneralRe: Attributes property Pin
MyThread1-Mar-05 6:58
MyThread1-Mar-05 6:58 
GeneralForms in DLL's in .Net Lightweight Pin
Tristan Rhodes1-Mar-05 5:59
Tristan Rhodes1-Mar-05 5:59 

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.