本文介绍了暂停线程,直到其他程序/进程完成运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我正在尝试在映射网络驱动器时暂停我的主线程,但每次网络驱动器映射的时间都不同。我不想使用Thread.Sleep(< static number =>)。

该程序如下:

线程T2 =  new 线程(()= >  
{
System.Diagnostics.Process.Start( net.exe @ 使用Z:\\Server-Share \My_Files \);
}
T2.Start();
T2.Join();
File.Copy( @ C:\daily_files\Updated_data.xlsx @ Z:\ Updated_data.xlsx true );



这里的问题是T2启动网络驱动器的映射,这需要3-5秒,主线程的下一步是复制粘贴文件到新的共享。复制粘贴开始时间早于网络共享映射完成 - 然后我得到错误,该位置不可用...所以 - 看起来网络共享映射正在其自己的线程中运行....

有谁知道如何使主线程等待共享驱动器映射完成?



非常感谢大家!

解决方案



Hello guys,
I''ve been trying to pause my main thread while the network drive is being mapped, but each time the time for network drive mapping is different. I don''t want to use Thread.Sleep(<static number="">).
The program is as follows:

Thread T2 = new Thread(() =>
{
System.Diagnostics.Process.Start("net.exe", @"use Z: \\Server-Share\My_Files\");
}
T2.Start();
T2.Join();
File.Copy(@"C:\daily_files\Updated_data.xlsx", @"Z:\Updated_data.xlsx", true);


The problem here is that T2 starts the mapping of network drive, which takes 3-5 seconds and the next step in main thread is copy-paste file to that new share. And the copy-paste starts earlier then the network share mapping finishes - then I get error that location is not available... So - looks like the network share mapping is running in its own thread....
Does anyone know how to make main thread wait for the shared drive mapping to finish?

Thanks a lot guys!

解决方案



这篇关于暂停线程,直到其他程序/进程完成运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 04:40