I've created a winrt project. I'm using two methods one for inserting the data and other for fetching the data.I'm trying to save the data during a time trigger event. The data is not saved when I'm inserting the data in background. When I'm inserting a data using the same method on a button click event the code is working. Here is the code where I'm calling the method to insert the data:
public sealed class BackgroundTask:IBackgroundTask
{
public void Run(IBackgroundTaskInstance taskInstance)
{
ToastTemplateType toastTemplate = ToastTemplateType.ToastText02;
XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(toastTemplate);
XmlNodeList textElements = toastXml.GetElementsByTagName("text");
textElements[0].AppendChild(toastXml.CreateTextNode("Background Task"));
textElements[1].AppendChild(toastXml.CreateTextNode("I'm message from your background task!"));
Database d = new Database();
d.saveData("new entry"); //calling the method to insert the string
ToastNotificationManager.CreateToastNotifier().Show(new ToastNotification(toastXml));
}
}
The 'saveData'method:
public async void saveData(string data)
{
SQLiteAsyncConnection connection = new SQLiteAsyncConnection("TimeDb.db");
try
{
var Db = new Database() {
Data = data
};
await connection.InsertAsync(Db);
}
catch (Exception ex)
{
}
}
Aucun commentaire:
Enregistrer un commentaire