public void LoadTextureAsync(string uri, object token, ScriptObject completedDelegate)
{
BitmapImage bi = new BitmapImage();
bi.ImageFailed += delegate(object sender, System.Windows.ExceptionRoutedEventArgs e)
{
completedDelegate.Invoke("loadTextureCompleted", -1, -1, -1, token, new Object());
};
bi.ImageOpened += delegate(object sender, System.Windows.RoutedEventArgs e)
{
Texture t = new Texture(bi);
_textures[t.Id] = t;
completedDelegate.Invoke("loadTextureCompleted", t.Id, t.Width, t.Height, token, null);
};
//Make sure we download the texture now, without it being part of the DOM
bi.CreateOptions = BitmapCreateOptions.None;
bi.UriSource = new Uri(uri, UriKind.Absolute);
}