How to be notified when external process is killed?

How can I unload the DLLs from a killed process in C#?

  • I have been trying to replace some new file using C# after killing the process using process.kill(), but I am facing issues mentioning "The process cannot access the file because it is being used by another process." after i kill the process and try to replace files

  • Answer:

    First of all, try to find out what other processes are still holding a lock on the DLL file. You can do this with SysInternals Process Explorer. http://technet.microsoft.com/en-us/sysinternals/bb896653.aspx Make sure you launch Process Explorer with Administrator rights. Perform a handle search for the name of the DLL. This will scan the handles and process space of other applications, and list any applications that has a handle to that DLL. Without identifying what other processes are holding the DLL back, there is nothing else you can do. One possible way of avoiding a lock on a DLL is to make a shadow copy: copy the original DLL to a temporary folder (with a folder name generated from some nearly-unique random function), and then load the DLL from there. If there is ever a need to load a DLL with the same name but different content (say it has been recompiled), generate a new random folder name each time. You can see how it works by taking a look at the NUnit project. By default, it makes shadow copy of all of the DLLs (both the unit testing project and all of its dependencies).

Ryan Wong at Quora Visit the source

Was this solution helpful to you?

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.