예제 #1
0
        /// <summary>
        /// 设置线程,运行copy文件,它与代理CopyFile_Delegate应具有相同的参数和返回类型
        /// </summary>
        private void RunCopyFile()
        {
            if (!File.Exists(_DownloadPath))
            {
                Application.Current.Dispatcher.Invoke((Action)(() =>
                {
                    FormCommon.ShowErr("文件:" + _DownloadPath + "不存在!");
                    this.IsEnabled = true;
                }));
                return;
            }
            var    file   = new FileInfo(_DownloadPath);
            string toFile = this.SavePath + "\\" + file.Name;

            CopyFile(_DownloadPath, toFile, 1024, btnDownload); //复制文件

            Application.Current.Dispatcher.Invoke((Action)(() =>
            {
                var arge = new MyDownloadEventArge(AfterDownloadRoutedEvent, this);
                arge._TargetFileInfo = new FileInfo(toFile);
                RaiseEvent(arge);
            }));

            Thread.Sleep(0);     //避免假死
            ThdCopyFile.Abort(); //关闭线程
        }
예제 #2
0
        /// <summary>
        /// 打开文件浏览器
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnOpen_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            var op = new System.Windows.Forms.OpenFileDialog();

            //默认的打开路径
            if (!txtInput.Text.IsNullOrEmpty())
            {
                var file = new FileInfo(txtInput.Text);
                op.InitialDirectory = file.DirectoryName;
            }
            op.RestoreDirectory = true;
            //op.Filter = "所有文件(*.*)|*.* ";
            var result = op.ShowDialog();

            if (result == System.Windows.Forms.DialogResult.OK)
            {
                _Value    = op.FileName;
                _FileInfo = new FileInfo(op.FileName);
                var arge = new MyDownloadEventArge(AfterFileSelectEvent, this);
                arge._TargetFileInfo = new FileInfo(op.FileName);
                RaiseEvent(arge);
            }
        }