• 公司代码阅读笔记 记于 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  
    
    
  • 相关阅读:
    20200726 千锤百炼软工人第二十一天
    20200725 千锤百炼软工人第二十天
    20200724 千锤百炼软工人第十九天
    20200723 千锤百炼软工人第十八天
    20200722 千锤百炼软工人第十七天
    20200721 千锤百炼软工人第十六天
    剑指Offer_#64_求1+2+…+n
    剑指Offer_#63_股票的最大利润
    剑指Offer_#62_圆圈中最后剩下的数字
    剑指Offer_#61_扑克牌中的顺子
  • 原文地址:https://www.cnblogs.com/changweihua/p/3334396.html
Copyright © 2020-2023  润新知