I am used to Javascript where I can simply pass a function as a parameter to use as a callback later. It was nice and easy.
Now I am writing an app in c# and would like to accomplish the same thing.
Basically, my app is like the following and requires an authentication token. However, at the getData stage, if the token is expired, I need to call refreshToken(). How do I pass the callback function through refreshToken() so getData knows what to call when the token is refreshed?
Here’s a diagram of what I would do in Javascript, but would I go about doing this in C#, or just passing callbacks in general?:
getData(callback);
// Looks like the token is expired, exiting the getData function and refreshing token
refreshToken(function(){ getData(callback); });
// Token is refreshed, now call getData()
getData(callback);
// Callback is run
Or, alternatively, instead of using a ton of callbacks I could do the refreshToken call synchronously. However, RestSharp on WP7 for whatever reason isn’t showing Execute, just ExecuteAsync, which is what I use now. Does anyone know why this method doesn’t seem to exist for me?
There are no synchronous web calls in silverlight / wp7, so that is not a restsharp problem.
As arthur said you want delegates.