Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:
C#
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!
Posted
Updated 14-Apr-13 22:26pm
v2

Create an instance of System.Diagnostics.Process instead, set the StartInfo property and register a handler on Exited before calling Start. The Exited event is then fired when the process exits, at least that's how I read this[^] ;)
 
Share this answer
 
Comments
MK-Gii 16-Apr-13 2:43am    
Thanks mate - that was exactly what I was looking for.
I owe you beer now :)
jsolutions_uk 16-Apr-13 3:54am    
glad to be of help :)
 
Share this answer
 
Comments
MK-Gii 16-Apr-13 2:44am    
Thanks Babu. But you should have said "Book" instead of "article" :D It contains 200 pages :)
But it's damn interesting. I will definitely read that one as well to get a more in depth understanding about Threading - thanks a lot bro.
I owe you a beer too :)
[no name] 16-Apr-13 3:08am    
thanks Modestas.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900