Delegates?

vis781

Well-known member
Joined
Aug 30, 2005
Messages
2,016
Location
Cambridge, UK
Programming Experience
5-10
Hi, i know that this is a massive subject and not one that could be discussed in full on a single thread. But i have just started using them and have a couple of questions. I have read many articles but i can't find a simple yes/no answer.

1. Do delegates automatically start their operation on a separate thread.
2. Is it ok to declare a shared delegate.
3. When should you use a thread from system.threading as opposed to a delgate?

thanks for reading. I hope i've been clear enough.
 
Last edited:
I was wondering how you came with these questions ... knowing that delegates are not really complicated. "For me" all three questions are meanless ... for instance, i don't see any reason why you would not declare shared delegates except that these delegates must be instantiated, whether or not they are ever used.
Anyway, guessing that nobody else will give an additional answer to this i would ask what is your intention and what you want to achieve by using delegates? Or maybe you are only studying about delegates at the moment and there are many unknowns :p


Regards ;)
 
Last edited:
Hi thanks for the reply,
What it is, is that i have read many articles on delegates and none of them are really basic enough for a beginner like me. I suppose my question about the shared delegates was a bit stupid and i can answer that one for myself.
But the other two do confuse me. i'll try to explain...

Delegates have two methods of starting their operation..

VB.NET:
Invoke.
BeginInvoke

Now these obviously don't do the same thing, but if you use either one would the function that the delegate points to start on a new thread, or is only one of them ment for asnychronus operations
 
Invoke is a synchronous operation, i.e. it does not return until the operation completes. BeginInvoke is an asynchronous operation, i.e. it returns immediately. The method that the delegate represents is executed in the thread in which the control on which Invoke or BeginInvoke was called was created, which will almost invariably be the main, or UI, thread. For example, if you call myForm.Invoke(...), the method you specify will be executed on whichever thread created the myForm object. You would almost never create controls on any thread but the main thread, so that's where the method will normally be executed.
 
Kulrom said:
Much clearer what? the difference between Invoke and BeginInvoke? Isn't it so obvious by meaning of words only? However i am glad that it is much clearer now for you.

All things are obvious to those who understand wouldn't you say. I would hardly say that 'BeginInvoke' automatically leads people to believe that it performs asynchronus operations just by the meaning of the words.

If you don't understand then you should ask, or is that not the point of these types of forums
 
Back
Top