问题
Hello i was wondering is it possible to have my program always look for updates like in the background always have a app looking for updates so when i pass a application update there is a little notification that pops up saying there is a update available for my program because currently i have a message box when the program launches and i wanted to have a icon in the task bar like java and when i pass a update a little prompt pops up saying there is a update waiting ?
this is a pic of what i want to do notification
and this is the code i have currently for checking for updates.
public void CheckForUpdates()
{
try
{
CleanUp();
WebClient downloadClient = new WebClient();
downloadClient.DownloadFile(UpdateUrl, LocalUpdateFile);
downloadClient.Dispose();
if (!File.Exists(LocalUpdateFile))
throw new FileNotFoundException("The local update file is missing!", LocalUpdateFile);
UpdateSaveFile localFile = DecodeSaveFile(LocalUpdateFile);
Version localVersion = Assembly.GetEntryAssembly().GetName().Version;
Version onlineVersion = Version.Parse(localFile.VersionString);
if (onlineVersion > localVersion)
{
if (DevExpress.XtraEditors.XtraMessageBox.Show(String.Format("Version {0} available,\nInstall it now?", onlineVersion.ToString()), "Elfenliedtopfan5 BO3 Weapon Adder Updater.", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)//MessageBox.Show(String.Format("Version {0} available,\nInstall it now?", onlineVersion.ToString()), "Youtube Updater", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
frmUpdater updateForm = new frmUpdater(localFile, GetPath(UpdateUrl));
updateForm.ShowDialog();
}
}
else
{
Message_elf msg = new Message_elf("You already have the latest version!", "elfenliedtopfan5 weapon adder 2016");
//MessageBox.Show("You already have the latest version!", "Youtube Updater", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
catch (Exception e)
{
MessageBox.Show("Error checking for updates\ntry again later!\n\nError Message:" + e.Message, "Youtube Updater", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
and i can call it via my main form like this.
updater1.CheckForUpdates();
any help would be much appropriated.
回答1:
Rather than create a service and have that thing running all the time in the background -- what a lot of companies do now is create a task scheduler task during the installation process. That task scheduler process runs every now and then to check for an update and you could build in a taskbar UI component to this utility that shows up while it's running and displays a "toast" notification as you screenshot when an update is available.
来源:https://stackoverflow.com/questions/41232170/c-sharp-show-notification-prompting-a-update