I need to create a callback method for my Commit method, just to know when it finished. So anyone know how to do that, how can I be able to call the commmit, then subscribe to the callback event/method to do other stuff when it is done.
Typically, in C#, you would do this via an event. The most common method for handling this would be to use the Event-based Asynchronous Programming model. This would define your API, by convention, as:
public void YourMethodAsync() {} // starts your method
public Event EventHandler<YourEventArgs> YourMethodCompleted; // Event used to receive completion notification
That being said, if you're developing for .NET 4, you might want to consider designing your method around the Task or Task<T> class, instead. Instead of creating a callback, you can return a Task directly. This allows your user to create a task continuation that runs when the operation completes. In addition, future versions of C# will allow the user to take advantage of the await and async keywords currently in CTP form to ease development.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With