Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

async HTTP GET Sample with Event Programming Model (EPM)

  • Loading branch information...
commit b33d1a435c076c7138c1d1aa2e7b3adf81c05f8f 1 parent e1a5827
@prabirshrestha prabirshrestha authored
Showing with 41 additions and 1 deletion.
  1. +41 −1 README.md
View
42 README.md
@@ -102,4 +102,44 @@ public static Task<string> GetAsyncTaskSample(CancellationToken cancellationToke
}
});
}
-```
+```
+
+#### Asynchronous Sample with Event Programming Model (EPM)
+
+*Available in all .NET plaforms.*
+
+Make an asynchrounous GET request to https://graph.facebook.com/4 and call the callback on completion.
+`Action<string, object, bool, Exception>` is mapped to response string, userState, isCancelled and Exception.
+
+```csharp
+public static void GetAsyncSample(Action<string, object, bool, Exception> callback = null, object userState = null)
+{
+ var httpHelper = new HttpHelper("https://graph.facebook.com/4");
+
+ httpHelper.OpenReadCompleted +=
+ (o, e) =>
+ {
+ if (callback == null)
+ return;
+
+ if (e.Cancelled)
+ callback(null, e.UserState, true, null);
+ else if (e.Error != null)
+ callback(null, e.UserState, false, e.Error);
+ else
+ {
+ using (var stream = e.Result)
+ {
+ using (var reader = new StreamReader(stream))
+ {
+ callback(reader.ReadToEnd(), e.UserState, false, null);
+ }
+ }
+ }
+ };
+
+ httpHelper.OpenReadAsync(userState);
+}
+```
+
+You can cancel the asynhrouns requests for EPM using `httpHelper.CancelAsync()` method.
Please sign in to comment.
Something went wrong with that request. Please try again.