Skip to content

Instantly share code, notes, and snippets.

@cfeckardt
Created September 29, 2013 08:43
Show Gist options
  • Save cfeckardt/6750542 to your computer and use it in GitHub Desktop.
Save cfeckardt/6750542 to your computer and use it in GitHub Desktop.
class Example {
someAsyncronousMethod(void * completed ) {
// This methods takes a long time, and runs on a separate thread so that it doesn't block execution.
// When we are done ...
if(completed != NULL)
(*completed)();
}
}
void foo() {
std::cout << "Our long running method has completed."
}
int main(int argc, char ** argv) {
Example ex;
void * foo = &foo
ex.someAsyncronousMethod(fooPtr);
while(true) {
//Event loop
}
return 0;
}
class MyWindow : Window
{
Button _button;
public MyWindow()
{
_button = new Button();
// place the button in the window
_button.Click += MyWindow.ButtonClicked;
}
static void ButtonClicked(object sender, RoutedEventArgs e)
{
MessageBox.Show("Button Clicked");
}
}
// The callback interface
interface MyCallback {
void callbackCall();
}
// The class that takes the callback
class Worker {
MyCallback callback;
void onEvent() {
callback.callbackCall();
}
}
// Option 1:
class Callback implements MyCallback {
void callbackCall() {
// callback code goes here
}
}
worker.callback = new Callback();
// Option 2:
worker.callback = new MyCallback() {
void callbackCall() {
// callback code goes here
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment