I am working on a WP8 application that uses ScheduledTaskAgent to update Live Tile. This is actually a fairly simple application. The problem is that although I directly copied the code from the WP7 project to the WP8 project, it will not start ScheduledTask. Not only that, but I get an error if I am debugging, and I am trying to run a scheduled task for testing.
System.Windows.ni.dll has occurred
Not only that, but he doesnโt give me any stack to look at, and says that the source is not available, and I can look at the disassembly in the disassembly window, which means nothing to me. So, not a very useful mistake, IMO.
I tried to set a breakpoint in the constructor of a scheduled task, and it never does that. If I comment out the launch for the test, no errors. But, of course, adding the application to his phone, it never started, leaving it overnight.
Here is my code:
var taskName = "TileUpdater"; var oldTask = ScheduledActionService.Find(taskName) as PeriodicTask; if (oldTask != null) { ScheduledActionService.Remove(taskName); } if (useLiveTile) { //GenerateTileInfo(); PeriodicTask task = new PeriodicTask(taskName); task.Description = AppResources.BackgroundTaskDescription; oldTask = ScheduledActionService.Find(taskName) as PeriodicTask; if (oldTask == null) { ScheduledActionService.Add(task); }
The code works fine in WP7.:/
This is in my WMAppManifest.xml file:
<ExtendedTask Name="BackgroundTask"> <BackgroundServiceAgent Specifier="ScheduledTaskAgent" Name="xxxScheduledTask" Source="xxxScheduledTask" Type="xxxScheduledTask.SecheduledAgent" /> </ExtendedTask>
In my scheduled task, the only thing I do is call the procedure, which generates information about the tile, updates the tiles, and at the moment I start the launch for the test, so I can watch to see if it is updated again, although I commented on it - I uncommented it to paste here, but it was commented out. Here is my OnInvoke method:
GenerateTileInfo(); #if DEBUG ScheduledActionService.LaunchForTest(task.ToString(), TimeSpan.FromSeconds(60)); #endif NotifyComplete();
The GenerateInfo method does nothing to cause the problem, but of course it never gets there. I tested my generation of tile information and its implementation by placing this code in MainPage.xaml.cs and calling it now to check if it works, and the code that I call works fine. Therefore, if I open the application, the tile will be updated. Now I need the background task to work.
Any help anyone can offer is greatly appreciated. Another hint is that last night I received an error message in which it was not possible to find the pdb file - I think it is Microsoft.Phone.pdb, but whatever it was, it also referred to System.Windows The .ni.dll file, but now I do not get this pdb problem, it's just an InvalidOperationException. Last night, debugging symbols (I don't know what this means) did not load. Today they are. I do not know what I did to fix it. Perhaps it was a restart, as far as I know.
In addition, I tried to create a new project and copy my code into a new project, thinking that my project file may be damaged, but the error that I get now is the same as before, create a new project.
Again, any help is appreciated. Thanks.
(Edit - New comments added below this paragraph 12/29 at 11:34 EST) ================================ =================== ================================
I tried another experiment. I created a new project and copied / pasted the code from http://www.jeffblankenburg.com/2011/11/25/31-days-of-mango-day-25-background-agents/ to find out if I can debug attachment. I had to make a few minor changes to the code that Jeff Blankenburg wrote, because he claims that when adding a scheduled task project, he will automatically add the following code to the WMAppManifest.xml file that he did not. I did it manually.
I also changed the type of StandardTileData strong> to FlipTileData strong> (since this is what was the default in the WP8 project) in the code that is inserted into ScheduledAgent.cs.
In addition, the only thing I did that Jeff did not mention in his article was to add the necessary directives.
Given the results of this experiment, I think that perhaps I am looking at how my Visual Studio installation is corrupted. Do you agree? I think that uninstalling / reinstalling VS2012 and the sdk phone is what you need here, but since it takes so long, I wanted a different opinion. Thanks.
Update (1/4/2012) ========================================== =======================
The remote VS went through the registry, then reinstalled the VS2012 and SDK phone. Here is what I am getting now - at least now it will show me the stack trace:
[Relatively managed transition] System.Windows.ni.dll! MS.Internal.JoltHelper.OnUnhandledException (object sender, System.UnhandledExceptionEventArgs args) [Managed by natural transition] mscorlib.ni.dll! System.Reflection.RuntimeAssembly.nLoad (System.Reflection.AssemblyName fileName, string codeBase, System.Security.Policy.Evidence assemblySecurity, System.Reflection.RuntimeAssembly locationHint, ref System.Threading.StackCrawlMark stackMark, System. IntPtrFilePotPprpprpprfpprpprfprpprfprpprfprpprprp bool forIntrospection, bool suppressSecurityChecks) mscorlib.ni.dll! System.Reflection.RuntimeAssembly.InternalLoadAssemblyName (System.Reflection.AssemblyName assemblyRef, System.Security.Policy.Evidence assemblySecurity, System.Reflection.RuntimeAssembly reqAssembly, ref System.Threading.StackCrawlMark stackMark, System.IntHFoprrbr bool suppressSecurityChecks) mscorlib.ni.dll! System.Reflection.RuntimeAssembly.InternalLoad (string assemblyString, System.Security.Policy.Evidence assemblySecurity, ref System.Threading.StackCrawlMark stackMark, System.IntPtr pPrivHostBinder, bool forIntrospection) mscorlib.ni.dll! System.Reflection.RuntimeAssembly.InternalLoad (string assemblyString, System.Security.Policy.Evidence assemblySecurity, ref System.Threading.StackCrawlMark stackMark, bool forIntrospection) mscorlib.ni.dll! System.Reflection.Assembly.Load (assemblyString line) Microsoft.Phone.ni.dll! Microsoft.Phone.BackgroundAgentActivator.LoadEntryPointAssembly (string assemblyName) Microsoft.Phone.ni.dll! Microsoft.Phone.BackgroundAgentActivator.LoadAgent (string assemblyName, string typeName) Microsoft.Phone.ni.dll! Microsoft.Phone.BackgroundAgentActivator.Microsoft.Phone.IBackgroundAgentActivator.CreateBackgroundAgent (string assembly, typeinfo string) Microsoft.Phone.ni.dll! Microsoft.Phone.BackgroundAgentDispatcher.AgentRequest.Invoke () Microsoft.Phone.ni.dll! Microsoft.Phone.BackgroundAgentDispatcher.InvocationThread () mscorlib.ni.dll! System.Threading.ThreadHelper.ThreadStart_Context (object state) mscorlib.ni.dll! System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executeContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx) mscorlib.ni.dll! System.Threading.ExecutionContext.Run (Executing System.Threading.ExecutionContextContext, callback System.Threading.ContextCallback, object state, bool preserveSyncCtx) mscorlib.ni.dll! System.Threading.ExecutionContext.Run (System.Threading.ExecutionContext executeContext, System.Threading.ContextCallback callback, object state) mscorlib.ni.dll! System.Threading.ThreadHelper.ThreadStart () [Sent to a managed transient]
It is also believed that I am using a low memory emulator and I forgot that background agents are not allowed on low memory devices, but which emulator (or device) I use does not matter.