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:
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