锁定模拟器的屏幕时抛出WebException(WindowsPhone8)

时间:2014-03-03 11:39:06

标签: windows-phone-8 locking screen webexception

我有一个webrequest来获取一个xml.That工作得很好但是当我按下F12(锁定屏幕)而我的应用程序请求服务器时......我得到了一个WebException。
我使用taskCompeltionSource对象...
这是我的代码

 
public async Task<String> Query(DataRequestParam dataRequestParam)
        {

            _dataRequestParam = dataRequestParam;

            try
            {
                Result = "";
                Result = await myDownloadString(dataRequestParam);

            }

            catch (WebException we)//ERROR IS CAUGHT HERE
            {
                throw new WebException(we.Message);

            }
            catch (Exception ex)
            {
                throw new MyException(ex.Message);

            }

            return Result;
        }

        public static Task<string> myDownloadString(DataRequestParam dataRequestParam)
        {
            var tcs = new TaskCompletionSource<string>();
            var web = new WebClient();

            if (!string.IsNullOrEmpty(dataRequestParam.AuthentificationLogin))
            {
                System.Net.NetworkCredential account = new NetworkCredential(dataRequestParam.AuthentificationLogin, dataRequestParam.AuthentificationPassword);
                web.Credentials = account;
            }

                web.DownloadStringCompleted += (s, e) =>
                {
                    if (e.Error != null) tcs.TrySetException(e.Error);
                    else if (e.Cancelled) tcs.TrySetCanceled();
                    else tcs.TrySetResult(e.Result);
                };

                web.DownloadStringAsync(dataRequestParam.TargetUri);
                return tcs.Task;

        }

1 个答案:

答案 0 :(得分:0)

如果您没有disabled ApplisationIdleDetection,则在进入锁定屏幕时您的流程会停止 - 因此您可能会遇到异常 - 就像我在评论中所说的那样。禁用将解决此问题,但您必须了解一些事项: