重庆分公司,新征程启航

为企业提供网站建设、域名注册、服务器等服务

WPF中怎么通过线程使用ProcessBar

这期内容当中小编将会给大家带来有关WPF中怎么通过线程使用ProcessBar,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。

十余年的未央网站建设经验,针对设计、前端、开发、售后、文案、推广等六对一服务,响应快,48小时及时工作处理。网络营销推广的优势是能够根据用户设备显示端的尺寸不同,自动调整未央建站的显示方式,使网站能够适用不同显示终端,在浏览器中调整网站的宽度,无论在任何一种浏览器上浏览网站,都能展现优雅布局与设计,从而大程度地提升浏览体验。创新互联从事“未央网站设计”,“未央网站推广”以来,每个客户项目都认真落实执行。

方法示例:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace WpfTestProcessBar
{
 /// 
 /// MainWindow.xaml 的交互逻辑
 /// 
 public partial class MainWindow : Window
 {
  public delegate void ProgressDelegate(int percent);
  public MainWindow()
  {
   InitializeComponent();
   ProgressEvent += MainWindow_ProgressEvent;
   beginImport();
  }
  void MainWindow_ProgressEvent(int percent)
  {
   Dispatcher.Invoke(new Action(Pro.SetValue), System.Windows.Threading.DispatcherPriority.Background, new object[] { ProgressBar.ValueProperty, Convert.ToDouble(percent+ 1) });
   Dispatcher.Invoke(new Action(label.SetValue), System.Windows.Threading.DispatcherPriority.Background, new object[] { Label.ContentProperty, Convert.ToString((percent + 1)+"%") }); 

  }
  private event ProgressDelegate ProgressEvent;
  private void beginImport()
  {
   Pro.Maximum = 100;
   Pro.Value = 0;
   label.Content = "0%";
   ThreadPool.QueueUserWorkItem(state =>
   {
    Thread.Sleep(2000);
    for (int i = 0; i < 100; i++)
    {
     if (ProgressEvent != null)
     {
      ProgressEvent(i);
     }
     Thread.Sleep(10);
    }
   });
  }
 }
}

上述就是小编为大家分享的WPF中怎么通过线程使用ProcessBar了,如果刚好有类似的疑惑,不妨参照上述分析进行理解。如果想知道更多相关知识,欢迎关注创新互联行业资讯频道。


网站题目:WPF中怎么通过线程使用ProcessBar
本文来源:http://cqcxhl.cn/article/pccpig.html

其他资讯

在线咨询
服务热线
服务热线:028-86922220
TOP