我有一个应用程序,我在块上传文件。我的前端是WPF,我有一个进度条来显示文件上传进度(上传由单独的线程完成,并且进度条处于上载开始时由子线程调用的单独表单中)。WPF进度条不显示正确的进度
我发现文件中的块的总数来设置进度条的最大属性。
现在,每块载我以1
递增进度条的价值,但让我吃惊,进度条开始增加,但从来没有完成(即停止显示几个街区后,进度)。
这里是负责上传文件线程代码:
System.Threading.Thread thread = new Thread( new ThreadStart( delegate() { // show progress bar - Progress is the name of window containing progress bar Progress win = new Progress(); win.WindowStartupLocation = System.Windows.WindowStartupLocation.CenterScreen; win.Show(); // find number of blocks long BlockSize = 4096; FileInfo fileInf = new FileInfo(filename); long FileSize = fileInf.Length; long NumBlocks = FileSize/BlockSize; //set the min and max for progress bar win.Dispatcher.Invoke( new Action( delegate() { win.progressBar1.Minimum = 0; win.progressBar1.Maximum = NumBlocks; } ), System.Windows.Threading.DispatcherPriority.Render); //upload file while (true) { // code to upload the file win.Dispatcher.Invoke( new Action( delegate() { win.progressBar1.Value += 1; } ), System.Windows.Threading.DispatcherPriority.Render); } }
有人可以帮我分析一下,为什么会出现这种情况。
谢谢。
你期望的人来调试你的代码,而不必*该代码的任何*? – 2011-04-23 01:23:48
我很抱歉,从下次开始请记住,谢谢 – Jake 2011-04-23 01:26:40
您可以编辑您的问题并添加代码。你应该这样做。 – 2011-04-23 01:27:42