В первую очередь: у меня нет опыта в объектно-ориентированном программировании. Я создал свою долю в сценариях VB и немного Java в школе, но это так. Так что моя проблема, скорее всего, лежит там. Но, тем не менее, за последние несколько дней я пытался собрать небольшое приложение, которое позволяет сканировать, выбирать и устанавливать обновления для Windows. До сих пор я мог понять большинство ссылок и с помощью нескольких сообщений в Интернете, и теперь я нахожусь в точке, где я могу выбирать и загружать обновления.
До сих пор мне удалось загрузить коллекцию обновлений, используя следующий код:
UpdateCollection CurrentInstallCollection = (UpdateCollection)e.Argument;
UpdateDownloader CurrentDownloader = CurrentSession.CreateUpdateDownloader();
CurrentDownloader.Updates = CurrentInstallCollection;
Это выполняется в фоновом рабочем столе и возвращается после завершения загрузки. Он работает очень хорошо, я вижу, что обновления загружаются в файловую систему, но на самом деле нет способа показать прогресс в приложении. Чтобы сделать это, есть интерфейс IDownloadJob, который позволяет мне использовать метод .BeginDownload загрузчика (UpdateSession.CreateUpdateDownloader)... я думаю, по крайней мере.: D И здесь возникает проблема: я сейчас пробовал около 6 часов, чтобы заставить код работать, но независимо от того, что я пробовал, ничего не сработало. Кроме того, в Интернете мало информации о методе .BeginDownload(или, по крайней мере, так кажется), но мой вызов метода не работает:
IDownloadJob CurrentDownloadJob = CurrentDownloader.BeginDownload();
Я не знаю, какие аргументы для поставки... Я пробовал методы, объекты... безрезультатно. Полный блок кода выглядит следующим образом:
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);
Я нашел один источник в Интернете, который вызвал метод с .BeginDownload(this,this,this)
, который не сообщает о какой-либо ошибке в редакторе кода, но, вероятно, не поможет в отчетности, поскольку я понимаю, что предоставленные аргументы методы, вызываемые при возникновении описанного события (прогресс был изменен или загрузка завершена).
Я также пробовал это, но он тоже не работал:
http://social.msdn.microsoft.com/Forums/en/csharpgeneral/thread/636a8399-2bc1-46ff-94df-a58cebfe688c
Подробное описание метода BeginDownload:
http://msdn.microsoft.com/en-us/library/aa386132(v=VS.85).aspx
Ссылка WUAPI:
К сожалению, мне не разрешено размещать ссылку, но ссылка на метод BeginDownload идет в том же месте.:)
Я знаю, это довольно немного, чтобы спросить, но если кто-то может указать мне в правильном направлении (как в каких аргументах пройти и как), это было бы очень признательно!:)