Click here to Skip to main content
15,888,293 members
Please Sign up or sign in to vote.
4.47/5 (4 votes)
I am using C# .net 4.5 While the application is connecting to a shared path and copying files. This is done using impersonisation. But after running once the code, I can see that the connection is alive to that server, although no data is being transferred. Note: I am using Resource Monitor to observe.
How do I efficiently close the connection/stop the process after the task is done.
Also the same I need to implement for managing windows services and task schedulers for remote.
The application (right now console app) sequentially makes multiple connection to multiple server, hence need to clear the memory immediately.

Below is the code snippet:
C#
string fileName = "test.zip";
            using(Impersonation.LogonUser("domainname","username","password",LogonType.NewCredentials))
            {
                File.Copy("\\shareddrivepath\"+ fileName, Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\" + fileName, 

     }

The Impersonation class is from https://github.com/mj1856/SimpleImpersonation

I had change the implementation as shown on http://msdn.microsoft.com/en-us/library/w070t6ka(v=vs.110).aspx

Please suggest how do I close the connection which is in open state, this run in process svchost.exe
Posted
Comments
DamithSL 5-May-14 6:13am    
can you show your code after changes?
[no name] 5-May-14 6:57am    
Maybe this helps?
WNetCancelConnection2

1 solution

WNetCancelConnection2

As idle63 said.
 
Share this answer
 

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