小编Sun*_*nic的帖子

UWP检查当前页面的名称或实例

在我的UWP应用程序中,我从协议或吐司开始.在onactivated方法中,我想检查应用程序的主视图是打开还是显示它的页面.全部来自App.xaml.cs

我想做的事情如下:

If Mainpage is not showing --> Navigate(typeof(MainPage));
Run Code Online (Sandbox Code Playgroud)

要么

If main window is not open since i am coming from protocol or toast launch
open frame and navigate to mainpage.
Run Code Online (Sandbox Code Playgroud)

不确定如何去做.

c# windows windows-runtime win-universal-app uwp

5
推荐指数
1
解决办法
6612
查看次数

UWP Httpclient postasync在后台任务中使用json字符串

我只想在我的UWP应用程序中将一些json从后台任务发布到api,然后取回响应来读取它.我的后台任务经常失败

Platform :: DisconnectedException ^在内存位置0x077FEE74.

我尝试了很多方法来使用互联网上的东西,但只是稍微调整失败.没有代码,我可以完美地执行后台任务.

这里的代码:

public async void Run(IBackgroundTaskInstance taskInstance)
        {
            _deferral = taskInstance.GetDeferral();

HttpClient aClient = new HttpClient();

            aClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            aClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("text/javascript"));



        Uri theUri = new Uri("https://m.xxxx.com/api/v4/session?expand=account,profile)");

StringContent theContent = new StringContent("{ \"keep_login\": true, \"id\": null, \"username\": \"zumbauser\", \"password\": \"zumbapw\" }", Encoding.UTF8, "application/json");


        HttpResponseMessage aResponse = await aClient.PostAsync(theUri, theContent);

        if (aResponse.IsSuccessStatusCode)
        {
            Debug.WriteLine("This is outpuuuuuuuuuuuuuut: " + aResponse.ToString());
        }
        else
        {
            // show the response status code 
            String failureMsg = "HTTP Status: " + aResponse.StatusCode.ToString() + " …
Run Code Online (Sandbox Code Playgroud)

json httpclient background-task uwp windows-10-universal

5
推荐指数
1
解决办法
983
查看次数