zoukankan      html  css  js  c++  java
  • 公司代码阅读笔记 记于 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  
    
    
  • 相关阅读:
    【转】理解Ruby的4种闭包:blocks, Procs, lambdas 和 Methods
    折腾weibo开放平台
    netsh——常用命令及使用技巧
    The Enemies of Achievement
    java内存模型
    命名规则
    JS 控制加载页面对象
    点击图片弹出上传文件对话框
    ASP.NET判断用户是否在线
    ASP.Net处理QueryString函数汉字参数传递错误
  • 原文地址:https://www.cnblogs.com/changweihua/p/3334396.html
Copyright © 2011-2022 走看看