Skip to content

Instantly share code, notes, and snippets.

@timheuer
Created August 27, 2012 20:35
Show Gist options
  • Save timheuer/3492033 to your computer and use it in GitHub Desktop.
Save timheuer/3492033 to your computer and use it in GitHub Desktop.
Async Void method from JavaScript
function dostuff() {
var j = document.getElementById("mycontent");
j.innerText = "";
var b = new WindowsRuntimeComponent6.Class1();
var c = b.initializeAsync().done(onStuffComplete, onStuffError);
}
function onStuffComplete() {
var j = document.getElementById("mycontent");
j.innerText = "the function completed";
}
function onStuffError() {
var j = document.getElementById("mycontent");
j.innerText = "the function had an error";
}
public IAsyncAction InitializeAsync()
{
return AsyncInfo.Run(async delegate
{
var storagefile = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFileAsync(@"WindowsRuntimeComponent6\TextFile1.txt");
using (var strm = await storagefile.OpenStreamForReadAsync())
{
using (StreamReader rdr = new StreamReader(strm))
{
string data = rdr.ReadToEnd();
}
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment