0

如果有人对我的 WyUpdate 应用程序为什么不想工作有任何反馈,请告诉我。

我正在尝试创建一个启动 WyUpdate 进程的基本控制台应用程序,然后在完成时执行我的主应用程序(刚刚更新)。

按照http://wyday.com/wybuild/help/silent-update-windows-service.php上的说明,我一点运气都没有。应用程序运行,并执行“ForceCheckForUpdate”过程,但我没有收到任何反馈:(

这是我的代码的完整列表。

我添加了一个 while 循环,希望能捕捉到来自 auBackend 的响应,但这似乎不起作用。有没有一种简单的方法可以同步运行进程并在关闭应用程序之前等待响应?

提前致谢。

使用系统;
使用 System.Threading;
使用 wyDay.Controls;

命名空间 NPS.CeAUpdateLauncher { 课堂节目 { 私有静态 AutomaticUpdaterBackend auBackend; 私人静态布尔接收反馈;

static void Main(string[] args) { auBackend = new AutomaticUpdaterBackend { //TODO: set a unique string. // For instance, "appname-companyname" GUID = "CeALauncher_AutoUpdate", // With UpdateType set to Automatic, you're still in // charge of checking for updates, but the // AutomaticUpdaterBackend continues with the // downloading and extracting automatically. UpdateType = UpdateType.Automatic, }; auBackend.CheckingFailed += auBackend_CheckingFailed; auBackend.UpdateAvailable += auBackend_UpdateAvailable; auBackend.DownloadingFailed += auBackend_DownloadingFailed; auBackend.ExtractingFailed += auBackend_ExtractingFailed; auBackend.ReadyToBeInstalled += auBackend_ReadyToBeInstalled; auBackend.UpdateSuccessful += auBackend_UpdateSuccessful; auBackend.UpdateFailed += auBackend_Failed; // Initialize() and AppLoaded() must be called after events have been set. // Note: If there's a pending update to be installed, wyUpdate will be // started, then it will talk back and say "ready to install, // you can close now" at which point your app will be closed. auBackend.Initialize(); auBackend.AppLoaded(); if (!auBackend.ClosingForInstall) { //TODO: do your normal service work CheckForUpdates(); } // while(!receivedFeedback) Thread.Sleep(10000); } static void CheckForUpdates() { // Only ForceCheckForUpdate() every N days! // You don't want to recheck for updates on every app start. if (//(DateTime.Now - auBackend.LastCheckDate).TotalDays > 10 && auBackend.UpdateStepOn == UpdateStepOn.Nothing) { auBackend.ForceCheckForUpdate(); } } static void auBackend_CheckingFailed(object sender, FailArgs e) { receivedFeedback = true; } static void auBackend_UpdateAvailable(object sender, EventArgs e) { receivedFeedback = true; } static void auBackend_DownloadingFailed(object sender, FailArgs e) { receivedFeedback = true; } static void auBackend_ExtractingFailed(object sender, FailArgs e) { receivedFeedback = true; } static void auBackend_ReadyToBeInstalled(object sender, EventArgs e) { // ReadyToBeInstalled event is called when // either the UpdateStepOn == UpdateDownloaded or UpdateReadyToInstall if (auBackend.UpdateStepOn == UpdateStepOn.UpdateReadyToInstall) { //TODO: Delay the installation of the update until // it's appropriate for your app. //TODO: Do any "spin-down" operations. auBackend.InstallNow() will // exit this process using Environment.Exit(0), so run // cleanup functions now (close threads, close running programs, // release locked files, etc.) // here we'll just close immediately to install the new version auBackend.InstallNow(); } receivedFeedback = true; } static void auBackend_UpdateSuccessful(object sender, SuccessArgs e) { receivedFeedback = true; } static void auBackend_Failed(object sender, FailArgs e) { receivedFeedback = true; } }

}

4

2 回答 2

1

使用我在最初的帖子中附加的代码,问题是控制台应用程序将无限期地运行。我认为那是因为 wyUpdate 进程从未返回值。我发现这是因为我没有提出所有事件。

在为“UpToDate”实现事件处理程序后,我收到了响应,并且能够设置指示器以使应用程序成功退出。

我还按照供应商的说明替换了布尔指示器和等待对“resetEvent”的响应的“while”方法,它工作得很好。

静态只读 ManualResetEvent resetEvent = new ManualResetEvent(false);

静态无效主要(字符串 [] 参数)
        {
          ...
          auBackend.UpToDate += auBackend_UpToDate;
          ...

          // 阻塞,直到另一个线程上的“resetEvent.Set()”
          resetEvent.WaitOne();

        }

静态无效 auBackend_UpToDate(对象发送者,SuccessArgs e)
        {
            重置事件.Set();
        }
    

感谢您的回复。

如果有人需要一个非常通用的应用程序更新解决方案,我建议使用 wyBuild/wyUpdate 包。

开心!

于 2011-03-25T02:21:54.797 回答
0

如果您能够使用Reactive Extensions for .NET (Rx),那么我有一个更简单的选择。

只要AutomaticUpdaterBackend该类在后台线程上触发其事件,那么此代码就应该执行您想要的操作:

void Main(string[] args)
{
    var auBackend = new AutomaticUpdaterBackend
    {
        GUID = "CeALauncher_AutoUpdate",
        UpdateType = UpdateType.Automatic,
    };

    var checkingFailed = Observable.FromEvent<FailArgs>(h => auBackend.CheckingFailed += h, h => auBackend.CheckingFailed -= h);
    var updateAvailable = Observable.FromEvent<EventArgs>(h => auBackend.UpdateAvailable += h, h => auBackend.UpdateAvailable -= h);
    var downloadingFailed = Observable.FromEvent<FailArgs>(h => auBackend.DownloadingFailed += h, h => auBackend.DownloadingFailed -= h);
    var extractingFailed = Observable.FromEvent<FailArgs>(h => auBackend.ExtractingFailed += h, h => auBackend.ExtractingFailed -= h);
    var readyToBeInstalled = Observable.FromEvent<EventArgs>(h => auBackend.ReadyToBeInstalled += h, h => auBackend.ReadyToBeInstalled -= h);
    var updateSuccessful = Observable.FromEvent<SuccessArgs>(h => auBackend.UpdateSuccessful += h, h => auBackend.UpdateSuccessful -= h);
    var updateFailed = Observable.FromEvent<FailArgs>(h => auBackend.UpdateFailed += h, h => auBackend.UpdateFailed -= h);

    var readyToBeInstalledStepReady = readyToBeInstalled.Where(e => auBackend.UpdateStepOn == UpdateStepOn.UpdateReadyToInstall);
    var readyToBeInstalledStepNotReady = readyToBeInstalled.Where(e => auBackend.UpdateStepOn != UpdateStepOn.UpdateReadyToInstall);

    var failed = Observable.Merge(new []
    {
        checkingFailed.Select(e => "Checking Failed"),
        downloadingFailed.Select(e => "Downloading Failed"),
        extractingFailed.Select(e => "Extracting Failed"),
        updateFailed.Select(e => "Update Failed"),
        readyToBeInstalledStepNotReady.Select(e => "Update Not Ready"),
    });

    var success = Observable.Merge(new []
    {
        readyToBeInstalledStepReady.Select(e => "Update Ready"),
        updateSuccessful.Select(e => "Update Successful"),
    });;

    failed.Subscribe(e => Console.Error.WriteLine(e));
    success.Subscribe(e => Console.WriteLine(e));

    readyToBeInstalledStepReady.Subscribe(e => auBackend.InstallNow());

    auBackend.Initialize();
    auBackend.AppLoaded();

    if (!auBackend.ClosingForInstall)
    {
        if (auBackend.UpdateStepOn == UpdateStepOn.Nothing)
        {
            auBackend.ForceCheckForUpdate();
        }
    }            

    success.Merge(failed).First();
}

是的,没有任何模块级变量,也没有事件处理程序方法。只是当地人和 lambdas。:-)

于 2011-03-24T07:39:41.143 回答