Displaying progress dialog only if a task did not finish in specified time

前端 未结 1 1230
青春惊慌失措
青春惊慌失措 2020-12-19 09:46

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

ImageInfo result = await service.UploadAsync(imagePath);

What I\'d l

相关标签:
1条回答
  • 2020-12-19 10:17

    May be something like this?

    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();
    }
    
    0 讨论(0)
提交回复
热议问题