Thanks Jennifer
Unfortunately that wasn't the problem though. I don't think i can do a query for attributes during a periodic task because its on the UI thread according to these responses from other people that got the same error.
I keep getting "Invalid cross thread access exception" when it hits
Code:
QueryTask queryTask =
new QueryTask("http://servicesbeta4.esri.com/arcgis/rest/services/SaveTheBay/FeatureServer/0");
and found these links for solutions http://stackoverflow.com/questions/8...-periodic-task
I don't have much time to mess with it, is it possible to run a attribute query during a periodic task?
Code:
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using System.Collections.Generic;
using System;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Data;
using ESRI.ArcGIS.Client;
using ESRI.ArcGIS.Client.Geometry;
using ESRI.ArcGIS.Client.Symbols;
using ESRI.ArcGIS.Client.FeatureService;
using ESRI.ArcGIS.Client.Tasks;
using Microsoft.Phone.Scheduler;
using System.Net;
namespace SeaLifeScheduledTask
{
public class ScheduledAgent : ScheduledTaskAgent
{
private static volatile bool _classInitialized;
// Activate identity manager.
/// <remarks>
/// ScheduledAgent constructor, initializes the UnhandledException handler
/// </remarks>
public ScheduledAgent()
{
IdentityManager.Current.ChallengeMethod = Challenge;
//ORGINIAL CODE HERE
if (!_classInitialized)
{
_classInitialized = true;
// Subscribe to the managed exception handler
Deployment.Current.Dispatcher.BeginInvoke(delegate
{
Application.Current.UnhandledException += ScheduledAgent_UnhandledException;
});
}
}
/// Code to execute on Unhandled Exceptions
private void ScheduledAgent_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)
{
if (System.Diagnostics.Debugger.IsAttached)
{
// An unhandled exception has occurred; break into the debugger
System.Diagnostics.Debugger.Break();
}
}
/// <summary>
/// Agent that runs a scheduled task
/// </summary>
/// <param name="task">
/// The invoked task
/// </param>
/// <remarks>
/// This method is called when a periodic or resource intensive task is invoked
/// </remarks>
protected override void OnInvoke(ScheduledTask task)
{
//TODO: Add code to perform your task in background
IdentityManager.Current.ChallengeMethod = Challenge;
//Intial Query to get scheduled Jobs
QueryTask queryTask =
new QueryTask("http://servicesbeta4.esri.com/arcgis/rest/services/SaveTheBay/FeatureServer/0");
queryTask.Credentials = new NetworkCredential("user1", "user1", "servicesbeta4.esri.com");
queryTask.ExecuteCompleted += QueryTask_ExecuteCompleted;
ESRI.ArcGIS.Client.Tasks.Query query = new ESRI.ArcGIS.Client.Tasks.Query();
query.Where = "Confirmed = '1'";
// This query will just populate the drop-down, so no need to return geometry
query.ReturnGeometry = false;
query.OutFields.Add("*");
queryTask.ExecuteAsync(query);
}
private void Challenge(string url,
IdentityManager.CredentialCompleteHandler callback,
IdentityManager.GenerateTokenOptions options)
{
// Pop-up dialog box to enter credentials - user action to call GenerateCredentialAsync.
IdentityManager.Current.GenerateCredentialAsync(url, "user1", "user1",
(credential, ex) =>
// lambda used to create anonymous block so call to GenerateCredentialAsync is self-contained.
{
callback(credential, ex);
},
options);
}
void QueryTask_ExecuteCompleted(object sender, ESRI.ArcGIS.Client.Tasks.QueryEventArgs args)
{
FeatureSet featureSet = args.FeatureSet;
//Get Total Jobs in Que
int JobCount = featureSet.Features.Count;
//string LastJobType = featureSet.Features
ShellTile PrimaryTile = ShellTile.ActiveTiles.First();
if (PrimaryTile != null)
{
StandardTileData tile = new StandardTileData();
//tile.BackgroundImage = new Uri("images/sadface.png", UriKind.Relative);
tile.Count = JobCount;
tile.Title = "added by background agent";
tile.BackTitle = "Get to work dude";
tile.BackContent = "Buddy";
PrimaryTile.Update(tile);
}
NotifyComplete();
}
}
}
Bookmarks