WyUpdate - C# 控制台应用程序,更新没有响应工作...如何运行同步?
如果有人对我的 WyUpdate 应用程序为何无法运行有任何反馈,请告诉我。
我正在尝试创建一个基本的控制台应用程序,该应用程序启动 WyUpdate 进程,然后在完成后执行我的主应用程序(刚刚更新)。
按照 http://wyday.com/wybuild/help/silent 上的说明进行操作-update-windows-service.php 给我一点运气都没有。应用程序运行,并执行“ForceCheckForUpdate”过程,但我没有收到任何反馈:(
这是我的代码的完整列表。
我添加了一个 while 循环以希望捕获来自 auBackend 的响应,但这并没有似乎不起作用。有没有一种简单的方法可以同步运行该进程并在关闭应用程序之前等待响应
?
using System; using System.Threading; using wyDay.Controls;命名空间 NPS.CeAUpdateLauncher { 班级计划 { 私有静态AutomaticUpdaterBackend auBackend; private static bool 收到反馈;
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; } }
}
If anyone has any feedback on why my WyUpdate application doesn't want to work please let me know.
I'm trying to create a basic console application which launches the WyUpdate process, and then on completion executes my main application (which has just been updated).
Following the instructions on http://wyday.com/wybuild/help/silent-update-windows-service.php gives me no luck at all. The application runs, and executes the "ForceCheckForUpdate" process, but I don't receive any feedback :(
here is a complete listing of my code.
I've added a while loop to hopefully catch the response from the auBackend, but that doesn't seem to work. is there an easy way to run the process synchronously and wait for the response before closing the application?
Thanks in advance.
using System; using System.Threading; using wyDay.Controls;
namespace NPS.CeAUpdateLauncher { class Program { private static AutomaticUpdaterBackend auBackend; private static bool receivedFeedback;
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; } }
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用我在第一篇文章中附加的代码,问题是控制台应用程序将无限期地运行。我认为这是因为 wyUpdate 进程从未返回值。我发现这是因为我没有提出所有事件。
在实现“UpToDate”的事件处理程序后,我收到了响应,并能够设置指示器以使应用程序成功退出。
我还按照供应商的说明替换了布尔指示器和等待“resetEvent”响应的“while”方法,并且它运行得很好。
感谢您的回复。
如果有人需要一个非常通用的应用程序更新解决方案,我建议使用 wyBuild/wyUpdate 包。
高兴!
With the code I attached in my initial post, the problem was that the console application would be running indefinitely. I thought that was because the wyUpdate process never returned a value. I found out it was because I didn't raise all events.
After implementing the eventhandler for "UpToDate" I received a response and was able to set the indicator to have the application exit successfully.
I also replaced the boolean indicator and the 'while' method of waiting for a response to the 'resetEvent' as per the vendor's instructions, and it is working very well.
Thanks for the responses.
If anyone ever needs a very versatile application updater solution, I would suggest the wyBuild/wyUpdate package.
Njoy!
如果您能够使用.NET (Rx) 反应式扩展< /a> 那么我有一个更简单的选择。
只要
AutomaticUpdaterBackend
类在后台线程上触发其事件,那么此代码就应该执行您想要的操作:是的,没有任何模块级变量,也没有事件处理程序方法。只有当地人和 lambda。 :-)
If you're able to use the Reactive Extensions for .NET (Rx) then I've got an easier alternative.
As long as the
AutomaticUpdaterBackend
class is firing its events on a background thread then this code should do what you want:Yes, there aren't any module-level variables and no event handler methods. Just locals and lambdas. :-)