线程睡眠在 Windows Phone 7 上运行不佳

编程入门 行业动态 更新时间:2024-10-23 14:22:37
本文介绍了线程睡眠在 Windows Phone 7 上运行不佳的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我想让我的程序休眠几秒钟.当我使用 thread.sleep(x) 时,整个程序没有响应.根据这篇文章 -> http://msdn.microsoft/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/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).

推荐答案

你需要重新思考暂停时你想做什么.鉴于我们没有太多关于您尝试通过此暂停实现什么的信息,这有点难说,但我将在这里举一个例子来说明如何在无需暂停整个应用程序的情况下获得想要的效果(这是你永远不应该做的).

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();
});

此外,最好使实际的下载调用异步(如果它正在下载您正在执行的操作),只是为了确保您不会影响 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, you can do both the downloads in the background-thread like this:

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

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

更多推荐

[db:关键词]

本文发布于:2023-04-25 14:12:13,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1117525.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:不佳   线程   睡眠   Windows   Phone

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!