• 公司代码阅读笔记 记于 2013-09-23


    标签: `代码` `C#` `WPF`
    
    **遍历文件夹下任意类型的文件**
    
    ```cs
        Loaded += delegate {
        
            var arr = "*.png|*.jpg|*.jpeg|*.gif".Split('|').SelectMany(filter => new DirectoryInfo(Environment.GetFolderPath(Environment.SpecialFolder.MyPictures)).GetFiles(filter, SearchOption.AllDirectories)).ToArray();
    
        };
    ```
    
    ---
    
    ```cs
    
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    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;
    using System.Windows.Threading;
    
    namespace CFileWall
    {
        /// 
        /// LoadingUserControl.xaml 的交互逻辑
        /// 
        public partial class LoadingUserControl : UserControl
        {
            public event EventHandler LoadingCompleted;
    
            public LoadingUserControl()
            {
                InitializeComponent();
                Loaded += new RoutedEventHandler(LoadingUserControl_Loaded);
            }
    
            void LoadingUserControl_Loaded(object sender, RoutedEventArgs e)
            {
                //启动新的线程加载文件
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(delegate
                {
                    int index = 1;
                    if (App.Files == null) return;
                    foreach (var file in App.Files)
                    {
                        this.Dispatcher.Invoke((Action)delegate
                        {
                            Console.WriteLine(index);
    
                            textBlock_LoadingTips.Text = index.ToString() + @"/" + App.Files.Length.ToString();
                            loadingProgress.Value = (double)index / App.Files.Length * 100;
                        }, null);
    
                        System.Threading.Thread.Sleep(100);
    
                        index++;
                    }
                    if (LoadingCompleted != null)
                    {
                        this.Dispatcher.BeginInvoke((Action)delegate
                        {
                            DispatcherTimer dt = new DispatcherTimer();
                            dt.Interval = TimeSpan.FromSeconds(1);
                            dt.Tick += delegate
                            {
                                dt.Stop();
                                LoadingCompleted(this, null);
                            };
                            dt.Start();
                        }, null);
                    }
                })).Start();
            }
        }
    }
    
    
    ```
    
    有问题或建议请反馈到:
    
    微博 :[@Changweihua](http://weibo.com/changweihua)
    
    邮箱 :changweihua@outlook.com  
    
    
  • 相关阅读:
    2级搭建类203-Oracle 19c SI ASM 静默搭建(OEL7.7)
    2级搭建类EM-Oracle EMCC 13c Release 3 在 OEL 7.7 上的搭建
    1级搭建类112-Oracle 19c SI FS(CentOS 8)
    0级搭建类013-CentOS 8.x 安装
    List添加map,后添加的map覆盖前面的问题
    mysql插入数据报错1366
    oracle ora-12514解决办法
    easyUI 创建详情页dialog
    Server Tomcat v7.0 Server at localhost failed to start.
    maven项目启动报错;class path resource [com/ssm/mapping/] cannot be resolved to URL because it does not exist
  • 原文地址:https://www.cnblogs.com/changweihua/p/3334396.html
Copyright © 2020-2023  润新知