Pergunta

I am using BackgroundUploader to upload video and I need to show notification when upload complete even when app is in background. for this I used toast notification when upload success, its working but only when app is in foreground(active) otherwise it shows when I activate app by clicking.I think this is because of app state suspended. my code is-

            if (response.StatusCode == 200)
            {
                ToastTemplateType toastTemplate = ToastTemplateType.ToastText01;
                XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(toastTemplate);

                XmlNodeList toastTextElements = toastXml.GetElementsByTagName("text");
                toastTextElements[0].AppendChild(toastXml.CreateTextNode("Video uploaded"));

                ToastNotification toast = new ToastNotification(toastXml);
                ToastNotificationManager.CreateToastNotifier().Show(toast);

                //some more work here
            }

Now i am trying to register background task which show notification and some other small thing after video upload complete.

Where to register background task and what trigger should I use?

or if any other possible solution for this?

Update-

I am using fallowing code to register Timer trigger with Background task

            string name = "UploadSuccess";
            bool registered = false;
            foreach (var task in BackgroundTaskRegistration.AllTasks)
            {
                //task.Value.Unregister(true);
                if (task.Value.Name.Equals(name))
                    registered = true;
            }
            if (registered == false)
            {
                var builder = new BackgroundTaskBuilder();
                builder.Name = name;
                builder.TaskEntryPoint = "VideoUploadSuccessTask.UploadSuccess";
                TimeTrigger t = new TimeTrigger(15, false);
                builder.SetTrigger(t);
                //builder.SetTrigger(new SystemTrigger(SystemTriggerType.ServicingComplete, false));

                var ret = builder.Register();
            }

and its working when debugging but never fires automatically :(

Foi útil?

Solução

In Windows 8, the best you can do where background tasks are concerned is a Timer trigger, but that gives you only a resolution of 15 minutes. It's a known deficiency for this scenario.

Fortunately, it's addressed in Windows 8.1, where the BackgroundTransfer API lets you configure a toast notification to be displayed when the transfer is complete. See the BackgroundUploader.SuccessToastNotification and FailureToastNotification properties.

I talk more about this in Chapter 4 of the second edition preview of my free ebook.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top