C# 为什么WP8应用程序中的JsonConvert.DeserializeObject可以工作,而非WP8 ScheduledTask';T

C# 为什么WP8应用程序中的JsonConvert.DeserializeObject可以工作,而非WP8 ScheduledTask';T,c#,json,windows-phone-8,json.net,background-process,C#,Json,Windows Phone 8,Json.net,Background Process,我在AWS中运行了一个REST服务,它返回一些信息。当我从应用程序中访问服务时,一切正常。当我在scheduledtask中使用完全相同的代码时,它不会。 奇怪的是,除了在Visual Studio中单步执行代码时,当在JsonConvert.DeserializeObject被调用的行中点击F10时,没有错误,没有异常,没有关于正在发生什么的提示。它不会跨过执行它的行,但它与点击F5相同 我的代码是: private void infoRetrieval_DownloadCompleted(o

我在AWS中运行了一个REST服务,它返回一些信息。当我从应用程序中访问服务时,一切正常。当我在scheduledtask中使用完全相同的代码时,它不会。 奇怪的是,除了在Visual Studio中单步执行代码时,当在
JsonConvert.DeserializeObject
被调用的行中点击F10时,没有错误,没有异常,没有关于正在发生什么的提示。它不会跨过执行它的行,但它与点击F5相同

我的代码是:

private void infoRetrieval_DownloadCompleted(object sender, DownloadStringCompletedEventArgs e)
{
    if (e.Error == null)
    {
        string response = e.Result;
        if (response != null)
        {
            try
            {
                CDateTime info = null;
                CJsonDateTime r = JsonConvert.DeserializeObject<CJsonDateTime>(response);
                info = new CDateTime(r);    

                if (info != null)
                {
                     // Indicate that there is a new info
                }
            } 
            catch (Exception exc)
            {
                // The exception can't be handled in a meaningful way, so it's ignored.
            }
       }
    }
}
private void infoRetrieval\u下载完成(对象发送方,DownloadStringCompletedEventArgs e)
{
如果(e.Error==null)
{
字符串响应=e.结果;
if(响应!=null)
{
尝试
{
CDateTime info=null;
CJsonDateTime r=JsonConvert.DeserializeObject(响应);
信息=新的CDateTime(r);
如果(信息!=null)
{
//指示有新的信息
}
} 
捕获(异常exc)
{
//无法以有意义的方式处理异常,因此将忽略它。
}
}
}
}
实际调用Web服务的代码如下所示,它也是我在应用程序和代理程序中作为OnInvoke方法的一部分使用的完全相同的代码:

infoRetrievalClient = new WebClient();
infoRetrievalClient.DownloadStringCompleted += new DownloadStringCompletedEventHandler(infoRetrieval_DownloadCompleted);
infoRetrievalClient.DownloadStringAsync(new Uri(<the URI to the webservice>));
infortrievalclient=newwebclient();
InformetrievalClient.DownloadStringCompleted+=新的DownloadStringCompletedEventHandler(Informetrieval\u DownloadCompleted);
下载StringAsync(新Uri());
请注意,我在应用程序和ScheduledTaskAgent中使用的代码完全相同。此外,我进行了检查,在这两种情况下检索到的字符串完全相同。这里的问题只是我不能解析JSON并使用数据

对NotifyComplete的调用在OnInvoke中

非常感谢您的任何帮助,因为我目前正陷于困境


我把它修好了,原来伊戈尔的问题让我走上了正轨。我将NotifyComplete移到了web请求的回调,现在所有的处理都很好

谢谢你,伊戈尔


Iwan

在计划任务中何时何地调用NotifyComplete()?OnInvoke是我执行请求的地方,它在WebClient取消回调中注册到“completed”事件。我相应地更新了我的问题。