zoukankan      html  css  js  c++  java
  • WPF 多线程处理(3)

    首先我们需要几个属性来保存取得的数据,因为在其他的线程中是不能读取控件的值.

            private string folderPath;
            private string[] files;
            private List<object> listItem;
    View Code

    再申明三个委托来分别执行这些数据,获取路径后读取路径下所有子文件, 更新到listbox上, 然后就是处理processBar.

            private Thread UpdateList = null;
            private Thread UpdateFolder = null;
            private Thread UpdatePBar = null;
    
            private delegate void UpdateListUI(object ob);
            private delegate void UpdateFolderPath(string path);
            private delegate void UpdatePBarUI(object obj);
    View Code

    然后注册事件:

            public MainWindow()
            {
                listItem = new List<object>();
    
                InitializeComponent();
    
                this.MouseDown+=(s,e)=>{
                    if (e.LeftButton == MouseButtonState.Pressed)
                    {
                        this.Cursor = System.Windows.Input.Cursors.Cross;
                        this.DragMove();
                    }
                };
                this.MouseUp += (s, e) => {
                    this.Cursor = System.Windows.Input.Cursors.Arrow;
                };
    
                btn_Top.Click += (s, e) => {
                    if (this.Topmost == true)
                    {
                        this.Topmost = false;
                    }
                    else
                    {
                        this.Topmost = true;
                    }
                };
    
                btn_Min.Click += (s, e) => {
                    this.WindowState = WindowState.Minimized;
                };
    
                btn_Close.Click += (s, e) =>
                {
                    this.Close();
                };
    
                btn_Broswer.Click += (s, e) => {
    
                    FolderBrowserDialog fbd = new FolderBrowserDialog();
                    fbd.RootFolder = System.Environment.SpecialFolder.DesktopDirectory;
                    fbd.ShowDialog();
                    StartBrowser(fbd.SelectedPath);
                };
    
                btn_Start.Click += (s, e) => {
                    UpdateList = new Thread(DoWork);
                    if (UpdateList.ThreadState == ThreadState.Running)
                    {
                        UpdateList.Abort();
                    }
                    UpdateList.Start();
                };
    
                this.listbox1.SelectionChanged += (s, e) => {
                    var lbi = this.listbox1.SelectedItem;
                    View view = new View(lbi);
                    view.ShowDialog();
                };
    
                this.Closing += (s, e) => {
                    StopWork();
                };
            }
    View Code

    下一篇:WPF 多线程处理(4)
    上一篇:WPF 多线程处理(2)

  • 相关阅读:
    git修改 config 配置用户名和邮箱
    Tranformer模型学习
    centos安装
    ubuntu cuda配置
    ubuntu安装python3.6
    flask后端部署
    linux基本操作
    python 基础数据结构
    文本特征选择
    常用笔记
  • 原文地址:https://www.cnblogs.com/fengqingyangNo1/p/3266013.html
Copyright © 2011-2022 走看看