I have a program the uses SQLite database to save app files. The most stable saving method I have is to manually click save button, other methods such as waiting for Suspension Event results in an unknown result (sometimes it stops saving at some random
point thus only the "early" part of my file are saved). Here is my saving method:
if (this->FlipViewCardDeck->Items->Size == 0) return;
this->_cardDeck.getCards()->clear();
for (int i = 0; i < FlipViewCardDeck->Items->Size; i++){
CCard* card = new CCard();
((CardView^) this->FlipViewCardDeck->Items->GetAt(i))->getCard(card);
this->_cardDeck.addCard(card);
}
Database db = Database();
db.init("test.db");
int id = db.insertCardDeck(_cardDeck);
_cardDeck.setId(id);
db.destroy();
I even tried wrapping it with
Dispatcher->RunAsync(Windows::UI::Core::CoreDispatcherPriority::Low, ref new Windows::UI::Core::DispatchedHandler([this](){
// Saving method from above here.
}));
but it made the unstable problem worse. The only way to ensure a solid save is to click the save button, which is a pain.
My Question is, in what event is it the best time to save, and how do I do it asynchronously?