c# - Program Terminates when Background Event Fire -
I have created a background text demo, it is 95 %% of a solution in question:
The full example of the solution can be downloaded here:
The problem occurs when my program schedule ends. The "My" solution can be downloaded here:
Here is the "My" code:
Applying the first class IBackgroundTask
System Use; Using System.Collections.Generic; Using System.Diagnostics; Using System.Linq; Using System.Text; System usage threading. Task; Using windows.ApplicationModel Background; Using Windows.Data.Xml.Dom; Using Windows.UI; information; Namespace class (public sealed class upload: iBkOfFounstsk {Public Zero Run (IBQFoundThask Intestate Task Intense) {debug.prakashline ("Hello IKkFormatsk"); // Return; Var toastXml = ToastNotificationManager.GetTemplateContent (ToastTemplateType.ToastText02); var textElements = toastXml Var.GetElementsByTagName ("text"); Var NetworkSetChangeEvents Detail = (Extend Descriptions as Trigger Windows.Networking Connectivity .networkState ChangesEvent Details); if (networ KStateChangeEventDetails == blank) Return; Text Elements [0] .AppendChild (toastXml.CreateTextNode ("I am a message from your work!")); ToastNotificationManager.CreateToastNotifier (). Show (New Toast Notification (Toast XML))}} }
And here is the code to enter the background text:
Private async zero Button_Click (Object Sender, RoutedEventArgs e) {Debug.WriteLine (" Registering work "); Var taskRegistered = false; Var Example TaskName =" UploadTask "; Forwarding (All tasks in the background job registration. All Tasks) {if (task.Value.Name == exampleTaskName) {// taskRegistered = true; Task.Value.Unregister (true); // break; }} Background Request the Execution Manager. RequestAssetSync (); If (! TaskRisisted) {Debug.WriteLine ("registering work inside"); Var Builder = New Background Task Builder (); Builder.Name = exampleTaskName; Builder. TaskEntryPoint = "Work Upload"; Builder. Satriger (New System Trigger (System Trigger Type. NetworkSaved Change, Incorrect)); BackgroundTaskRegistration Task = Builder. Registrar (); //task.completed + = new page geometriccompiled event handler (NetworkSetChangeTackoncomplicated); // Task. Trigger + = new page geometric compiled document handler (NetworkSetChangTackoncompiled); Wait a new message-dialog ("Task Registered!") ShowSync (); }} Private Zero NetworkState ChangeTechOnConnected (screenwriter letter transmitter, pgmtmuscate integrated event argues args) {var toastXml = ToastNotificationManager.GetTemplateContent (ToastTemplateType.ToastText02); Var textElements = toastXml.GetElementsByTagName ("text"); Text Elements [0] Appendibil (Toast XMLKTextNoode ("NetworkSetChangerTechoncompiled () =>")); Text Elements [0] .AppendChild (toastXml.CreateTextNode ("I am a message from your work!")); ToastNotificationManager.CreateToastNotifier (). Show (new Toast Notification (Toast XML)); }
I can not find any exceptions, and there is no error message. When the event just ends, the event fire. Similar to both devices and emulator
I've checked your project, to improve you Things are:
- First and foremost - Your background should be
Windows Runtime Component No class library ( As it is now) - open properties of background work and change it. Backgrounding should be to be a runtime component - that is why your program ends. - You have to change the namespace to the name of the project - in this case you
work.upload
(instead ofTasks.uppload
). Remember also to change the entry in package announcements in the package. Appxmanifest
In this form I have tried that your app should work properly.
Comments
Post a Comment