Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

callbacks in c#, calling order and return

Tags:

c#

callback

A simple question on callbacks. Do callback functions return to the next line in the calling function after completion ?

class A
{
 public delegate void A();
 public event A onA;

 public void func()
 {
   //some code 1
  onA();
  //some code 2 
 }

So the question is will onA event go and execute the respective handler and then come back to 'some code 2' bit or is this asynchronous and code will not wait for the event to be fully handled?

I hope the question is clear.

Thanks }

like image 344
user642770 Avatar asked May 12 '11 13:05

user642770


People also ask

What are callbacks in C?

A callback in C is a function that is provided to another function to "call back to" at some point when the other function is doing its task. There are two ways that a callback is used: synchronous callback and asynchronous callback.

Why do we use callback function in C?

The main advantage of using callbacks is that you can call a function that is defined in a higher software level from a lower software level subroutine. A callback can be used for notifications or signals.

What are callbacks used for?

Callbacks make sure that a function is not going to run before a task is completed but will run right after the task has completed. It helps us develop asynchronous JavaScript code and keeps us safe from problems and errors.

What do you mean by callbacks?

Callback Functions A callback function is a function that is passed as an argument to another function, to be “called back” at a later time. A function that accepts other functions as arguments is called a higher-order function, which contains the logic for when the callback function gets executed.


1 Answers

The way you used delegate: is synchronous. If you want asynchronous you must invoke delegate with: BeginInvoke method.

like image 112
VikciaR Avatar answered Oct 30 '22 14:10

VikciaR