Thread调用SaveFileDialog
Posted 小水皮
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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); }); } } }
以上是关于Thread调用SaveFileDialog的主要内容,如果未能解决你的问题,请参考以下文章
python opencv error “parallel_impl.cpp (240) WorkerThread 155: Can‘t spawn new thread: res = 11“(代码片
Java Thread 的 run() 与 start() 的区别