I've come across the same issue. It's been a nightmare. My app is also a win32 desktop app MSIX package. I'm confident to tell you that your app didn't try to restart. Instead, it crashed. If you read the health report from the Partner Center, you'll see all the crash incidents. And if you are like me, continue uploading new versions trying to make things work, you can easily relate the crash incidents to the latest builds.
After some trials, I found it was the call to TrySilentDownloadAndInstallStorePackageUpdatesAsync that caused the crashes. And the solution to the problem has amazed me. Although the documentation said that this method will download and install the updates, don't trust it!
Instead:
TrySilentDownloadStorePackageUpdatesAsync to download the updatesTrySilentDownloadAndInstallStorePackageUpdatesAsync only for installation!Then no crashes!
And to make your day easier, I'll post the whole damn thing here. Should save you days of work:
typedef void(*WindowsStoreCallback) (int error);
namespace winrt
{
using namespace winrt;
using namespace winrt::Windows::Services::Store;
using namespace winrt::Windows::Foundation;
using namespace winrt::Windows::Foundation::Collections;
}
winrt::Windows::Foundation::IAsyncAction TrySilentDownloadAndInstallUpdate(WindowsStoreCallback callback)
{
// return control to caller
co_await winrt::resume_background();
// check update
winrt::IAsyncOperation<winrt::IVectorView<winrt::StorePackageUpdate>> op_check = m_storeContext.GetAppAndOptionalStorePackageUpdatesAsync();
winrt::IVectorView<winrt::StorePackageUpdate> updates = co_await op_check;
if (updates.Size() <= 0) {
callback(E_FAIL); // handle any other ways to fit your need
co_return;
}
// Download only
winrt::IAsyncOperationWithProgress<winrt::StorePackageUpdateResult, winrt::StorePackageUpdateStatus> op_download =
m_storeContext.TrySilentDownloadStorePackageUpdatesAsync(updates);
bool is_completed = false;
while (!is_completed) { // I don't know if the loop is necessary, just added to be safe. The documentation is unclear anyway ...
winrt::StorePackageUpdateResult result = co_await op_download;
switch (result.OverallState()) {
case winrt::StorePackageUpdateState::Pending:
case winrt::StorePackageUpdateState::Downloading:
case winrt::StorePackageUpdateState::Deploying:
::Sleep(100);
continue;
case winrt::StorePackageUpdateState::Completed:
is_completed = true;
break;
case winrt::StorePackageUpdateState::Canceled:
callback(E_ABORT);
co_return;
// all other errors
case winrt::StorePackageUpdateState::OtherError:
case winrt::StorePackageUpdateState::ErrorLowBattery:
case winrt::StorePackageUpdateState::ErrorWiFiRecommended:
case winrt::StorePackageUpdateState::ErrorWiFiRequired:
default:
callback(E_FAIL);
co_return;
}
}
// (Download) and install
winrt::IAsyncOperationWithProgress<winrt::StorePackageUpdateResult, winrt::StorePackageUpdateStatus> op_install =
m_storeContext.TrySilentDownloadAndInstallStorePackageUpdatesAsync(updates);
while (true) { // Again, I don't know if the loop is necessary, just to be safe.
winrt::StorePackageUpdateResult result = co_await op_install; // Wait for completion
switch (result.OverallState()) {
case winrt::StorePackageUpdateState::Pending:
case winrt::StorePackageUpdateState::Downloading:
case winrt::StorePackageUpdateState::Deploying:
break;
case winrt::StorePackageUpdateState::Completed:
callback(S_OK);
co_return;
case winrt::StorePackageUpdateState::Canceled:
callback(E_ABORT);
co_return;
// all other errors
case winrt::StorePackageUpdateState::OtherError:
case winrt::StorePackageUpdateState::ErrorLowBattery:
case winrt::StorePackageUpdateState::ErrorWiFiRecommended:
case winrt::StorePackageUpdateState::ErrorWiFiRequired:
default:
callback(E_FAIL);
co_return;
}
::Sleep(100);
}
co_return;
}
Hope this help.
Sidenote: If someone can contact Microsoft team, please tell them to make the days of developers easier by giving out sample codes that work for ALL SUPPORTED LANGUAGEs (till today the "example" category for in the corresponding doc is still blank) and provide a simulator for testing! There is no fun deploying again and again just to test something such simple. And you know, I have to deploy TWICE every time I changed the code (one for the code changes, another one to feed the update). That's why I said it was a nightmare!