title: C# and WUAPI: BeginDownload function
body: <p>First things first: I have no experience in object-oriented programming, whatsoever. I created my share of VB scripts and a bit of Java in school, but that's it. So my problem most likely lies there. But nevertheless, for the past few days, I've been trying to get a little application together that allows me to scan for, select and install Windows updates. So far I've been able to understand most of the references and with the help of a few posts around the internet and I'm now at the point where I can select and download updates.</p>
  <p>So far I've been able to download a collection of updates using the following code:</p>
  <pre><code>UpdateCollection CurrentInstallCollection = (UpdateCollection)e.Argument;
  UpdateDownloader CurrentDownloader = CurrentSession.CreateUpdateDownloader();
  CurrentDownloader.Updates = CurrentInstallCollection;
  </code></pre>
  <p>This is run in a background worker and returns once the download is done. It works just fine, I can see the updates getting downloaded on the file system but there isn't really a way to display the progress within the application. To do such a thing, there is the IDownloadJob interface that allows me to use the <code>.BeginDownload</code> method of the downloader.</p>
  <p><code>UpdateSession.CreateUpdateDownloader</code> I think, at least. And here comes the problem: I have now tried for about 6 hours to get the code working, but no matter what I tried nothing worked. Also, there isn't much information around on the internet about the <code>.BeginDownload</code> method (or at least it seems that way), but my call of the method doesn't work:</p>
  <pre><code>IDownloadJob CurrentDownloadJob = CurrentDownloader.BeginDownload();
  </code></pre>
  <p>I have no clue what arguments to supply. I've tried methods, objects...to no avail. The complete block of code looks like this:</p>
  <pre><code>UpdateCollection CurrentInstallCollection = (UpdateCollection)e.Argument;
  UpdateDownloader CurrentDownloader = CurrentSession.CreateUpdateDownloader();
  CurrentDownloader.Updates = CurrentInstallCollection;
  IDownloadJob CurrentDownloadJob = CurrentDownloader.BeginDownload();
  IDownloadProgress CurrentJobProgess = CurrentDownloadJob.GetProgress();
  tbStatus.Text = Convert.ToString(CurrentJobProgess.PercentComplete);
  </code></pre>
  <p>I've found one source on the internet that called the method with <code>.BeginDownload(this, this, this)</code>, which does not report any error in the code editor but probably won't help with reporting as it is my understanding, that the arguments supplied are the methods that are called when the described event occurs (progress has changed or the download has finished).</p>
  <p>I also tried this, but it didn't work either:</p>
  <p><a href="http://social.msdn.microsoft.com/Forums/en/csharpgeneral/thread/636a8399-2bc1-46ff-94df-a58cebfe688c" rel="nofollow noreferrer">http://social.msdn.microsoft.com/Forums/en/csharpgeneral/thread/636a8399-2bc1-46ff-94df-a58cebfe688c</a></p>
  <p>A detailed description of the BeginDownload method:</p>
  <p><a href="http://msdn.microsoft.com/en-us/library/aa386132(v=VS.85).aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/aa386132(v=VS.85).aspx</a></p>
  <p>WUAPI Reference:</p>
  <p>Unfortunately, I'm not allowed to post the link, but the link to the <code>BeginDownload</code> method goes to the same place.</p>
  <p>I know, it's quite a bit to ask, but if someone could point me in the right direction (as in which arguments to pass and how), it'd be very much appreciated.</p>