线程睡眠不到风度上的Windows Phone7运行良好 [英] Thread sleep dosn't work well on Windows Phone7

查看:150
本文介绍了线程睡眠不到风度上的Windows Phone7运行良好的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望把我的计划,以睡眠为几秒钟。当我用了Thread.Sleep(x)的整个程序没有响应。根据这篇文章 - > 的http:// MSDN。 microsoft.com/en-us/library/hh184840(v=VS.92).aspx 应用程序,它不负责3秒不通过认证:/(我必须等待5秒钟)。是否有人知道这个问题的解决方案?

I want to put my program to a sleep for a couple of seconds. When i use thread.sleep(x) entire program doesn't respond. According to this article -> http://msdn.microsoft.com/en-us/library/hh184840(v=VS.92).aspx application which is not responsible for 3 seconds doesn't pass the certification :/ (i have to wait 5 seconds). Does anybody know a solution for this problem?

推荐答案

您需要重新考虑你正在尝试与你的停顿做。这是一个有点很难说因为我们没有关于你努力实现这个暂停什么太多的信息,但是我在这里举一个例子来说明如何可以得到想要的效果,而无需暂停整个应用程序( 。你永远不应该这样做)

You need to rethink what you are trying to do with your pause. It's a bit hard to say given that we don't have much info about what you try to achieve with this pause, but I'll give an example here to illustrate how you can get the wanted effect without having to pause the entire app (which you should never do).

比如说你要下载的文件A,然后等待5秒,然后下载文件B.通过运行像这样做:

Say you want to download file A, then wait 5 sec ,then download file B. You do this by running something like this:

var file = downloadFileA();
new Thread((ThreadStart)delegate
{
    Thread.Sleep(5000);
    downloadFileB();
});



此外,它prefferable使实际的下载通话异步(如果它正在下载你正在做的) ,只是为了确保你不feeze的GUI

Also, it's prefferable to make the actual download-calls async (if it is downloading you are doing), just to make sure that you don't feeze the GUI.

Alternativly,你可以在这样的背景线程执行两个下载:

Alternativly, you can do both the downloads in the background-thread like this:

new Thread((ThreadStart)delegate
{
    var file = downloadFileA();
    Thread.Sleep(5000);
    downloadFileB();
});

这篇关于线程睡眠不到风度上的Windows Phone7运行良好的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆