显示进度对话框只有一个任务,在指定时间内没有完成

编程入门 行业动态 更新时间:2024-10-14 22:13:54
本文介绍了显示进度对话框只有一个任务,在指定时间内没有完成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个小的服务,上传图片,我用它是这样的:

I have a little service that uploads an image, and I use it like this:

ImageInfo result = await service.UploadAsync(imagePath);

我想要做的是显示一个进度对话框,但只有当上载操作需要更多的比,也就是说,2秒。上传完成后,我想关闭进度对话框。

What I'd like to do is to display a progress dialog, but only if the upload operation takes more than, say, 2 seconds. After the upload is done, I want to close the progress dialog.

我在使用任务/ ContinueWith粗的解决方案,但我希望有更多的优雅的方式。

I made a crude solution using Task/ContinueWith, but I was hoping for a more "elegant" way.

我怎样才能做到这一点使用异步/计谋?

How can I achieve this using async/await?

推荐答案

可能是这样呢?

var uploadTask = service.UploadAsync(imagePath); var delayTask = Task.Delay(1000);//Your delay here if (await Task.WhenAny(new[] { uploadTask, delayTask }) == delayTask) { //Timed out ShowProgress ShowMyProgress(); await uploadTask;//Wait until upload completes //Hide progress HideProgress(); }

更多推荐

显示进度对话框只有一个任务,在指定时间内没有完成

本文发布于:2023-11-27 13:34:10,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1638289.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:时间内   只有一个   对话框   进度

发布评论

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

>www.elefans.com

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