0

What I think to myself - We use delegates with callBack functions to get something done asynchronously. We use either Func or Action for parameter and non, argument functions respectively.

[Correct me If I'm wrong] But, I am interested to know is there any scenario where I won't use any callback function instead just use a delegate to get something done asynchronously.

EDIT:

Delegates + Callback = Asynchronous programming.

Can I do asynchronous programming without callbacks, If yes then what are those scenarios?

Enigmativity
  • 113,464
  • 11
  • 89
  • 172
Iqra.
  • 685
  • 1
  • 7
  • 18
  • `Func` and `Action` _are_ delegates. They are predefined delegate types meant for general purpose use. I'm not sure what it is you're asking. – Abion47 May 18 '17 at 04:20
  • See the following on the "difference" between a delegate and a callback: http://stackoverflow.com/questions/290819/are-delegates-and-callbacks-the-same-or-similar – Abion47 May 18 '17 at 04:24
  • I am asking in terms of multi-threading and asynchronous programming, where delegates being used with a callback function, It is happening since .NET version1.0 (BeginInvoke/EndInvoke). I am asking is there any scenario where I need not to use callbacks but just delegate, If yes then would this approach remain Asynchronous? – Iqra. May 18 '17 at 04:29
  • 1
    Your question is difficult to understand due to imprecise use of terminology. However, it sounds like you are thinking of async operations where one passes a delegate instance referring to a callback method, so that method can be called when the operation completes, and are asking whether there are examples of async operations which don't use that mechanism. If so, then the answer is simply "of course"; it is idiomatically referred to as "fire and forget". – Peter Duniho May 18 '17 at 04:30
  • 1
    There are also async mechanisms that don't involve passing a callback delegate, such as the event-async model and `async`/`await`. But in those cases, delegates are still in use; they just are handled differently than being passed to the initiating method, and in the case of the latter, aren't even explicitly visible in the code. – Peter Duniho May 18 '17 at 04:30
  • 1
    Frankly, your use of `BeginInvoke`/`EndInvoke` as an example only further confuses matters. First, there are multiple classes with those methods: they exist on delegate types, as well as in the Winforms and WPF APIs. Second, the delegate type version of those methods is itself used directly as a way to execute an operation asynchronously, and may or may not involve _passing_ a callback method to the operation as a way of signaling completion (depending on usage). So if all you write is _"BeginInvoke/EndInvoke", we have no way to know for sure what context you are talking about. – Peter Duniho May 18 '17 at 04:32

0 Answers0