我已经创建了一个项目并添加了一个ScheduledTaskAgent并添加了此代码是OnInvoke函数
string toastMessage = "Periodic task running.";
ShellToast toast = new ShellToast();
toast.Title = "Background Agent Sample";
toast.Content = toastMessage;
toast.Show();
和WAAppManifast.xml代码
<Tasks>
<DefaultTask Name ="_default" NavigationPage="MainPage.xaml"/>
<ExtendedTask Name="BackgroundTask">
<BackgroundServiceAgent Specifier="ScheduledTaskAgent" Name="ScheduledTaskAgent1" Source="ScheduledTaskAgent1" Type="ScheduledTaskAgent1.ScheduledAgent" />
</ExtendedTask>
</Tasks>
并在MainPage.xaml代码中
public MainPage()
{
InitializeComponent();
StartPeriodicAgent();
// Sample code to localize the ApplicationBar
//BuildLocalizedApplicationBar();
}
private void StartPeriodicAgent()
{
AgentIsEnabled = true;
// If this task already exists, remove it
PeriodicTask =ScheduledActionService.Find(PeriodicTaskname ) as PeriodicTask;
if (PeriodicTask != null)
{
RemoveAgent( PeriodicTaskname );
}
PeriodicTask = new PeriodicTask(PeriodicTaskname);
PeriodicTask.Description ="This demonstrates a periodic task.";
try
{
ScheduledActionService.Add( PeriodicTask );
// PeriodicStackPanel.DataContext = PeriodicTask;
#if(DEBUG_AGENT)
ScheduledActionService.LaunchForTest(
PeriodicTaskname,
TimeSpan.FromSeconds( 2 ) );
#endif
}
catch (InvalidOperationException exception)
{
if (exception.Message.Contains(
"BNS Error: The action is disabled" ))
{
MessageBox.Show("Background agents for this applicationhave been disabled by the user." );
AgentIsEnabled = false;
// PeriodicCheckBox.IsChecked = false;
}
}
}
protected override void OnNavigatedTo(
System.Windows.Navigation.NavigationEventArgs e)
{
PeriodicTask =
ScheduledActionService.Find(PeriodicTaskname)
as PeriodicTask;
}
private void RemoveAgent(string PeriodicTaskname)
{
ScheduledActionService.Remove(PeriodicTaskname);
}
}
我在 OnNavigatedTo 函数中添加了一个调试,此函数运行正常,然后显示2秒错误后错误是 附加信息:无法加载文件或程序集“ScheduledTaskAgent1,Culture = neutral,PublicKeyToken = null”或其依赖项之一。系统找不到指定的文件。 我认为我的应用程序无法调用ScheduledTaskAgent OnInvoke函数 请帮助我在哪里犯错误