2
我做了一個後臺任務,使其在NetworkStateChange上偵聽,並且工作正常。從BackgroundTask執行程序
我試圖通過Windows.System.Launcher.LaunchUriAsync
推出一個計劃,但我在嘗試時訪問被拒絕例外:
下面是任務來源:
namespace Tasks
{
public sealed class Upload : IBackgroundTask
{
BackgroundTaskDeferral _deferral = null;
private bool wifiConnected = false;
public bool WiFiConnected
{
get
{
return wifiConnected;
}
set
{
if (value == wifiConnected)
return;
wifiConnected = value;
}
}
public void Run(IBackgroundTaskInstance taskInstance)
{
var InternetConnectionProfile = NetworkInformation.GetInternetConnectionProfile();
WiFiConnected = InternetConnectionProfile != null;
if (!WiFiConnected)
{
LaunchFlexCheck();
return;
}
_deferral = taskInstance.GetDeferral();
_deferral.Complete();
}
private async void LaunchFlexCheck()
{
Debug.WriteLine("BEFORE LaunchFlexCheck()");
bool result = false;
try
{
result = Windows.System.Launcher.LaunchUriAsync(new System.Uri("myapp:MainPage")).GetResults();
}
catch (Exception e)
{
result = false;
Debug.WriteLine("LaunchFlexCheck exception:" + e.Message);
}
Debug.WriteLine("LaunchFlexCheck succes:" + (result ? "true" : "false"));
Debug.WriteLine("AFTER LaunchFlexCheck()");
}
}
}
是更多鈔票是這樣做的?