SharpBox进度条为用户
我想在uploadFile期间向用户显示进度条。我可以通过下面的方法获得后端的百分比,但是我无法打印e.PercentageProgress返回的百分比以显示给用户。SharpBox进度条为用户
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;
}
限制:如果这对你的作品还是这个解决方案不是线程安全的。这意味着,您无法回应多次下载的进度。您一次只能使用一次下载。
希望这有助于...!
事情是SharpBox自动几次启动方法。即使我设置了Progress,我也需要在UploadDownloadProgress方法被触发时准确获取数据。我正在尝试这样的事情,并且值永远不会改变:perc.Text = docUpload.Progress.ToString(); –
因此,实际上我似乎需要管理在方法内获取百分比到UploadDownloadProgress –
这似乎并不那么容易实现。我不得不修改我的解决方案并首先在服务器上上传文件(我可以在其中轻松显示进度条),然后上传到Dropbox。这只会在后台运行,因此用户不需要被通知它,并会完成请求,无论用户停留或离开网站(网络方法)。另一个优点是上传时间大幅减少。 –