gpt4 book ai didi

c# - 用户的 SharpBox 进度条

转载 作者:太空宇宙 更新时间:2023-11-03 15:22:08 25 4
gpt4 key购买 nike

我试图在上传文件期间向用户显示进度条。我可以通过以下方法在后端获取百分比,但是我无法打印 e.PercentageProgress 返回的百分比以显示给用户。

  static void UploadDownloadProgress(Object sender, FileDataTransferEventArgs e)
{
// Need to show this on a label or return to front end somehow
System.Diagnostics.Debug.WriteLine(e.PercentageProgress);

e.Cancel = false;
}

问题是如何让 e.PercentageProgress 显示在 aspx 页面上或让它在 javascript 中使用?

最佳答案

尝试这样的事情:

public class ProgressInformer {

public static string Progress = "0";

static void UploadDownloadProgress(Object sender, FileDataTransferEventArgs e)
{

// print a dot
System.Diagnostics.Debug.WriteLine(e.PercentageProgress);

// Need to show this on a label or return to front end somehow
ProgressInformer.Progress = e.PercentageProgress.ToString();

e.Cancel = false;
}
}

现在,由于您正在为静态变量设置值,因此您可以从其他地方访问它。然后您可以使用该值通过某种方法或服务在前端回显。可能是这样的:

public string EchoToFrontEnd()
{
return ProgressInformer.Progress;
}

Limitation: If this works for you still this solution is not thread safe. That means, you cannot echo progress for multiple downloads. You'll have to work with a single download at a time.

希望这有助于...!

关于c# - 用户的 SharpBox 进度条,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36825667/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com