I was trying to update the UWP app(which is in store with higher version) through programmatically. But the problem is after downloading and installation process, as per MS docs not getting any OS popup that application is going to restart.
On completion, it just restart the app, also not reaching to "Completed" state.
Also In between Internet pause and restart automatically update the system, not providing control to developer.
Any Idea how to do that.
Doc link - https://learn.microsoft.com/en-us/windows/uwp/packaging/self-install-package-updates
AsyncOperationWithProgress<StorePackageUpdateResult, StorePackageUpdateStatus> downloadOperation1 =
updateManager.RequestDownloadAndInstallStorePackageUpdatesAsync(updates);
downloadOperation1.Progress = async (asyncInfo, progress) =>
{
await Task.Run(() =>
{
this.ProgressUpdateValue = progress.PackageDownloadProgress;
}).ConfigureAwait(true);
};
StorePackageUpdateResult downloadResult1 = await downloadOperation1.AsTask().ConfigureAwait(true);
switch (downloadResult1.OverallState)
```
Related
I am using BackgroundDownloader in my UWP app like:
private async void StartDownload()
{
var destinationFile = await KnownFolders.VideosLibrary.CreateFileAsync("temp.zip", CreationCollisionOption.GenerateUniqueName);
var backgroundDownloader = new BackgroundDownloader();
var downloadOperation = backgroundDownloader.CreateDownload(fileUrl, destinationFile);
SendUpdatableToastWithProgress();
var progressCallback = new Progress<DownloadOperation>();
progressCallback.ProgressChanged += ProgressCallback_ProgressChanged;
var opProgress = await downloadOperation.StartAsync().AsTask(progressCallback);
}
private void ProgressCallback_ProgressChanged(object sender, DownloadOperation e)
{
if (e.Progress.TotalBytesToReceive > 0)
{
var br = e.Progress.BytesReceived;
var percent = br * 1.0 / e.Progress.TotalBytesToReceive;
UpdateToastProgress(percent);
}
}
Is there any chance how can I get ProgressChanged fired even the UWP App is closed?
There is currently no reliable option on how to update BackgroundDonwloader progress in Toast notification through Progress<DownloadOperation>.
As per Microsoft documentation, BackgroundTask could be suspended or killed based on the actual system state. That could happen before the BackgroundDownloader finishes its job and your Toast notification will look like it got frozen.
The best approach here is to update your Toast progress bar in the app suspended or exited event with AdaptiveProgressBarValue.Indeterminate with appropriate texting (e.g. Finishing download in background, etc.). Based on comments from #Faywang - MSFT you can still get notifications about successful or failed download even the app is closed or suspended.
Another approach would be to use extendedExecutionUnconstrained to be able to run BackgroundTask indefinitely. In that case, you would be able to update Toast progress with 'live' data and even more, to trigger new download via BackgroundDownloader. The downside of this approach is that your app cannot be listed in Microsoft Store.
My goal is to update the build's pool information to move the queued build/build into another pool via the REST API. I have tried a lot of things and cannot find any documentation - not even on which parameters can actually be set
Code I have tried to accomplish this task with:
try
{
build.Queue.Id = newQueue.Id;
build.Queue.Name = newQueue.Name;
build.Queue.Pool = new Microsoft.TeamFoundation.Build.WebApi.TaskAgentPoolReference();
build.Queue.Pool.Name = newQueue.Pool.Name;
build.Queue.Pool.Id = newQueue.Pool.Id;
build.Queue.Pool.IsHosted = newQueue.Pool.IsHosted;
var c = connection.GetBuildClient();
var tf = await c.UpdateBuildAsync(build);
return true;
}
catch (Exception ex)
{
return false;
}
(the above code is very hacky as I am attempting to make it work)
Things I have tried:
1) I have tried copying the exact json and sending it via a raw patch request, then I get a response saying that it is modified. But NOTHING is modified except the last modified user changing to me
2) I have tried editing the AgentsPoolQueue in the request body via the API, but it is not the pool I want to change - but the Build's pool information to link to another build instead.
update the build's pool information to move the queued build/build
into another pool via the REST API
After testing, updating the queued build's agent pool through the rest API is currently not supported in Azure Devops . Once build is run, its agent pool information cannot be modified.
Although the AgentPoolQueue is recorded in the request body in the Update-build rest api document. However, when you actually use it, you will find that the return status is 200 ok, but the pool information in the build has not actually been updated. This is not stated in the documentation and it does cause confusion.
The agent pool is determined when you run pipeline. Once the build is running, even in the queue state, it cannot be changed. You could submit your request for this feature on our UserVoice site, which is our main forum for product suggestions. More votes and comments can increase the priority of feedback.
At present, you can only cancel the queued builds, run new builds, and re-specify the agent pool in the new builds.
You need to update the Build using the existing Build id
public async Task<Build> UpdateBuildAsync(Build build, string id)
{
var updateBuild = await Repository.GetBuildAsync(id);
if (updateBuild != null)
{
updateBuild.Timestamp = DateTime.Now;
updateBuild.Status = build.Status;
updateBuild.Description = build.Description;
if (build.Status == (int)BuildStatus.BuildQueued)
{
updateBuild.VSTSBuildId = build.VSTSBuildId;
}
if (build.Status == (int)BuildStatus.DeploymentQueued)
{
updateBuild.TemplateParameterUri = build.TemplateParameterUri;
updateBuild.TemplateUri = build.TemplateUri;
}
updateBuild.PkgURL = build.PkgURL;
await Repository.UpdateBuildAsync(updateBuild);
return await Repository.GetBuildAsync(id);
}
return updateBuild;
}
I have the same problem as this guy over here: UWP Timetrigger not working
but I can't comment the question because my reputation is not high enough, so I'm creating a new question.
As I said, I have the same problem. I registered the background task, but nothing happens. My background task is located in a seperate project (Runtime Component). So that's not the problem.
This is the method I made to register the task:
public static BackgroundTaskRegistration Register(string name, string taskEntryPoint, IBackgroundTrigger trigger, IBackgroundCondition condition)
{
var foundTask = BackgroundTaskRegistration.AllTasks.FirstOrDefault(x => x.Value.Name == name);
if (foundTask.Value != null)
return (BackgroundTaskRegistration)foundTask.Value;
var builder = new BackgroundTaskBuilder();
builder.Name = name;
builder.TaskEntryPoint = taskEntryPoint;
builder.SetTrigger(trigger);
if (condition != null)
builder.AddCondition(condition);
return builder.Register();
}
and this is how I call it:
BackgroundTaskRegister.Register(nameof(NotificationTask), $"Epguides.Background.{_backgroundTaskName}", new TimeTrigger(30, true), null);
When I debug my application and use Lifecycle Events in Visual studio to test my background task, everything works fine. So the problem is not the task.
When I inspect the BackgroundTaskRegistration result I see that the property trigger is null. on the MSDN page of BackgroundTaskRegistration.Trigger it says the following
This is not intended for use in your code. For all unsupported trigger types, the value returned by this property is null.
So from what I understand is that TimeTrigger is an unsupported trigger type, because Trigger is null.
This is what is declared in the manifest file
Is there someone that can explain why it is not working. I'm using version 10.0.10586
You can confirm that the your task is registered or not by using powershell.
Open powershell with administrative rights, and run 'Get-AppBackgroundTask'. All of registered tasks are listed. If you can't find your task from the list, there are some problems at registration.
Have you add the background task project as a reference to your main app?
Have you call the BackgroundExecutionManager.RequestAccessAsync()? You should call it before registering, from UI thread.
I have a sample app of background task with timetrigger on the store. It's hidden from storefront and search, but you can download it from following link:
https://www.microsoft.com/store/p/ddlgbgtasktrial/9nblggh4s785
This app regist a simple background task with 15min interval timetrigger. This task just output the debugmessage to the logfile. The app shows a log. If it works well, you can see the debug output with about 15min intervals.
I've confirmed that the app works with Win10 desktop 10586.494 and mobile 14393.0.
I had exactly same problem with TimeTrigger (Application trigger was working without any issues) and I followed every step from MSDN regarding BackgroundTask in UWP. But ONLY below "magic line" helped me to solve - BIG THANKS to #Canol Gökel for his reply in comments (I think it deserve separate answer):
BackgroundExecutionManager.RemoveAccess(); // This is the magic line!
var backgroundAccessStatus = await BackgroundExecutionManager.RequestAccessAsync();
Time trigger is part of UWP background task sample (Scenario 4) which was working for me. But this line is not used there at all. Instead it is used in NFC sample during check if application was updated:
private static async Task<bool> DoBackgroundRequestAccess()
{
String appVersion = String.Format("{0}.{1}.{2}.{3}",
Package.Current.Id.Version.Build,
Package.Current.Id.Version.Major,
Package.Current.Id.Version.Minor,
Package.Current.Id.Version.Revision);
if ((string)Windows.Storage.ApplicationData.Current.LocalSettings.Values["AppVersion"] != appVersion)
{
// Our app has been updated
Windows.Storage.ApplicationData.Current.LocalSettings.Values["AppVersion"] = appVersion;
// Call RemoveAccess
BackgroundExecutionManager.RemoveAccess();
}
BackgroundAccessStatus status = await BackgroundExecutionManager.RequestAccessAsync();
return status == BackgroundAccessStatus.AlwaysAllowed
|| status == BackgroundAccessStatus.AllowedSubjectToSystemPolicy;
}
I have a UAP application, and when I debug on a Windows 10 Phone, IBackgroundTask is triggered automatically. When I debug on Local Machine (Windows 10 x86), it isn't called at all. How can I trigger it?
A simple way is to set a system trigger. In your manifest, you need a "Background Tasks" declaration, with a "System event" property.
In your C# code, you have to register your task and you can bind the task to a particular event system like "NetworkStateChange" :
foreach (var task in BackgroundTaskRegistration.AllTasks)
{
task.Value.Unregister(true);
}
var result = await BackgroundExecutionManager.RequestAccessAsync();
if (result == BackgroundAccessStatus.Denied)
{
return;
}
BackgroundTaskBuilder builder = new BackgroundTaskBuilder();
builder.Name = "<task name>";
builder.TaskEntryPoint = "<task entry point>";
builder.SetTrigger(new SystemTrigger(SystemTriggerType.NetworkStateChange, false));
var registration = builder.Register();
With this code, you can launch the task with a manual manipulation on the network (switch wifi or unplung your cable).
When debugging, you can trigger a background task directly from Visual Studio 2015. There's a drop-down menu called Lifecycle Events that lets you invoke Suspend, Resume and any registered background tasks. Set a breakpoint in your task beforehand. (In my case the class implementing the background task is called NotifyChanges.)
I'm trying to register a background task and I'm getting some strange behaviour. I appears that the task itself is registering and firing at the right time; however, when it does fire it's closing my program down (with no error).
I suspect that the reason is linked to the fact that the program is not asking me is I want to allow a background task to run when I launch. I have created a declaration for the background task as a system event, and am registering like this from the App.Xaml.cs:
var builder = new BackgroundTaskBuilder();
builder.Name = "NewTask";
builder.TaskEntryPoint = "ConnectionMonitor.CheckInternet";
builder.SetTrigger(new SystemTrigger(SystemTriggerType.InternetAvailable, false));
BackgroundTaskRegistration task = builder.Register();
So, I believe my question is: why would it not ask me for permission to run a background task (which I assume will give me the answer to my main problem of why it is crashing)?
I'm not sure whether it matters, but this is a Windows Universal app (the app.xaml.cs above is in the Shared project.
The task looks like this:
BackgroundTaskDeferral _deferral = taskInstance.GetDeferral();
bool newConnected = IsConnected();
if (connected != newConnected)
{
connected = newConnected;
var notifier = ToastNotificationManager.CreateToastNotifier();
var template = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText02);
var element = template.GetElementsByTagName("text")[0];
element.AppendChild(template.CreateTextNode(connected ? "Connection available" : "Connection lost"));
var toast = new ToastNotification(template);
notifier.Show(toast);
}
_deferral.Complete();
You asked: why would it not ask me for permission to run a background task?
The answer is, unless your background task requires lock screen access, it does not require the user's permission to be registered. There is no user prompt, by design. One of the intents of this design is that it allows you to register a task from another task.
In Windows, you do not need to call BackgroundExecutionManager.RequestAccessAsync() except for lock screen access. Calling it will give you more quota but will require the user to approve the task.
In Windows Phone, calling RequestAccessAsync() is required no matter what, but never prompts the user with a UI. For this reason the logic in your Universal App can be shared but will likely have a #if to handle the registration differently, if relevant.