Cannot create a BitmapImage; IsDownloading always true

  • Thread starter Thread starter Jeff S.
  • Start date Start date
J

Jeff S.

No matter what I try, the following application never does anything except
print,
True
True
True
...
It is a console app that attempts to leverage the WPF. I cannot for the
LIFE of me figure out why none of the BitmapImage's events fire, and why it's
IsDownloading property always reports true.


using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Net;
using System.Threading;
using System.Web;
using System.Windows.Media;
using System.Windows.Media.Imaging;

namespace MyNamespace {
class Program {
static void Main(string[] args) {
BitmapImage image = new BitmapImage();
image.BeginInit();
image.DownloadCompleted += new EventHandler(image_DownloadCompleted);
image.DownloadFailed += new
EventHandler<ExceptionEventArgs>(image_DownloadFailed);
image.DownloadProgress += new
EventHandler<DownloadProgressEventArgs>(image_DownloadProgress);
image.CreateOptions = BitmapCreateOptions.IgnoreImageCache;
image.CacheOption = BitmapCacheOption.None;
image.UriSource = new
Uri("http://www.google.com/intl/en_ALL/images/logo.gif");
image.UriCachePolicy = new
System.Net.Cache.RequestCachePolicy(System.Net.Cache.RequestCacheLevel.BypassCache);
image.DecodeFailed += new
EventHandler<ExceptionEventArgs>(image_DecodeFailed);
image.EndInit();

while (true) {
Console.WriteLine(image.IsDownloading);
Thread.Sleep(1000);
}
}

static void image_DecodeFailed(object sender, ExceptionEventArgs e) {
Console.WriteLine("Decode failed!");
}

static void image_DownloadProgress(object sender,
DownloadProgressEventArgs e) {
Console.WriteLine("Progress!");
}

static void image_DownloadFailed(object sender, ExceptionEventArgs e) {
Console.WriteLine("Failure!");
}

static void image_DownloadCompleted(object sender, EventArgs e) {
Console.WriteLine("Completed!");
}
}
}
 
Back
Top