zoukankan      html  css  js  c++  java
  • Thread调用SaveFileDialog

            public void ThreadSaveFileDialog(string sourceFileName)
            {
                Thread importThread = new Thread(new ParameterizedThreadStart(SaveDialog));
                importThread.SetApartmentState(ApartmentState.STA); //重点
                importThread.IsBackground = true;
                importThread.Start(sourceFileName);
    
            }
    
    
            public static MainForm ScratchForm;//这个是主窗口
            private void SaveDialog(object sourceFileName)
            {
                SaveDialogShow(sourceFileName as string);
    
            }
    
            delegate void SaveDialogShowCallBack(string sourceFileName);
            private void SaveDialogShow(string sourceFileName)
            {
           //判断主窗口是否跨线程调用
    if (ScratchForm.InvokeRequired) { SaveDialogShowCallBack stcb = new SaveDialogShowCallBack(SaveDialogShow); ScratchForm.Invoke(stcb, new object[] { sourceFileName }); } else {
              //将saveFileDialog附加上主From上,否则的话点击主窗口会把savefiledialog给遮挡住。重复点击保存会弹出多个savefiledialog result
    = ScratchForm.saveFileDialog.ShowDialog(ScratchForm); if (result == DialogResult.OK) { string destFileName = ScratchForm.saveFileDialog.FileName; Task.Run(() => { File.Copy(sourceFileName, destFileName, true); }); } } }
  • 相关阅读:
    点子
    点子
    ruby crawler Anemone
    创业站
    我友网 没前途
    创意
    电商站
    尿布
    创意
    青番茄好项目
  • 原文地址:https://www.cnblogs.com/xbzhu/p/9095305.html
Copyright © 2011-2022 走看看