First of all, these links may be of interest:
Asynchronous call of synchronous methods
Do I need to delegate .EndInvoke ()?
Now about your questions:
The call code is immediately returned to the comment control when it falls into the BeginInvoke line.
Yes, the call is executed asynchronously (I can assume that it is using a different thread).
Does this mean that the following code (EndInvoke, followed by some trace tracking) is executed only after calling FooWithOutAndRefParameters completes ... automatically (although this code is in the same method). It bothers me a bit. (I always used callbacks for this kind of thing.)
EndInvoke blocks execution until the thread (method) initiated by BeginInvoke completes. In this context, it is similar to threading.
Using this method, I have to call EndInvoke. Can I just call the method asynchronously and forget that this happened? Any flaws in this?
You should always call EndInvoke (see below). There are probably many reasons for this, but the one that, in my opinion, is most important is that if the method fails, by throwing an exception, you will not get the exception until EndInvoke is called.
If I do not call EndInvoke (as shown in this method), then should I always have a callback? Even if the callback does nothing.
The callback should call EndInvoke in this case, from the callback. Thus, only a callback is optional.
If the answers you MUST ... then you call EndInvoke OR define a Call Back? (The advantage of defining a callback is that you are notified of the result)
You do not need to define a callback, but if you do, you call it in EndInvoke.
You better understand which scenario is better: notify, completely asynchronously, that the method is finished or forcibly connects to the method (thus blocking the calling thread). It's all about control, and you have to do one or the other, or even both.
By the way, I know that I can check for errors or logical results in EndInvoke or callback (and I could do that). I was wondering if ARE IS RISK from not calling EndInvoke or defining a callback (memory leak, for example)? What is the best practice.
Not at its core, no, I don't think there are risks. But you should always check if the method was unsuccessful or completed successfully.
From MSDN , here are options for what can be done after BeginInvoke:
Follow some steps and then call EndInvoke to block until the call ends.
Get WaitHandle using the IAsyncResult.AsyncWaitHandle property, use the WaitOne method to block execution until WaitHandle is called and then call EndInvoke.
Interrogate the IAsyncResult returned by BeginInvoke to determine when the asynchronous call has completed, and then call EndInvoke.
Pass the delegate to the callback method for BeginInvoke. This method is executed on the ThreadPool thread when the asynchronous call completes. The callback method calls EndInvoke.
OBS: As @ScottChamberlain said in the comments, MSDN states that :
You can call EndInvoke to get the return value from the delegate, if necessary, but not required. EndInvoke blocks until a return value is received.
I think the reason is that when working with Controls, you are working in a user interface thread. Since EndInvoke blocks the thread, there may be reasons why you do not want to do this. However, I would recommend using a callback or polling to complete to make sure the method completed successfully. This will make your program more reliable (or error resistant).