I have some SQL code with local database in my App, it works:
using(var ctx = new TestCTX()){
var res = ctx.Test.ToList();
}
Then I want to use it in PeriodicTask in OnInvoke method, I get
UnauthorizedAccessException
:
public override void OnInvoke(ScheduledTask){
using(var ctx = new TestCTX()){
var res = ctx.Test.ToList();
}
}
But then I wrap it to:
public override void OnInvoke(ScheduledTask task){
Deployment.Current.Dispatcher.BeginInvoke(()=>{
using(var ctx = new TestCTX()){
var res = ctx.Test.ToList();
}
});
}
Then it works. So here is the question: Why must I wrap it into BeginInvoke ?