Executing and then deleting a DLL in C #

I am creating a self-updating application where I have most of the code in a separate DLL. This is the command line and will eventually be run on Mono. I'm just trying to get this code to work in C # on windows on the command line.

How can I create a C # application that I can remove the supporting dll during its launch?

AppDomain domain = AppDomain.CreateDomain("MyDomain");
ObjectHandle instance = domain.CreateInstance( "VersionUpdater.Core", "VersionUpdater.Core.VersionInfo");
object unwrap = instance.Unwrap();
Console.WriteLine(((ICommand)unwrap).Run());
AppDomain.Unload(domain);
Console.ReadLine();

in ReadLine the VersionUpdater.Core.dll file is still locked from deletion

The ICommand interface is located in the VersionUpdater.Common.dll file, which is referenced by both the Commandline application and VersionUpdater.Core.dll

+2
source share
4 answers

, - - , - DLL AppDomain , . AppDomain, DLL .

, exe, AppDomain. , stub exe , , AppDomain, .

. DLL , DLL , , . , . , AppDomain, .

+6

Unwrap , . - "" , command.run, appdomain. , , .

+1

, , .

, . , temp, (System.Diagnostics.Process.Start()), , : " ". exe.

exe , , , . . exe .

- . .

+1

MOVEFILE_DELAY_UNTIL_REBOOT . , , , , ; DLL explorer.exe DLL ..

MoveFileEx MSDN;

lpNewFileName [in, ] .

. , MOVEFILE_COPY_ALLOWED dwFlags.

.

dwFlags MOVEFILE_DELAY_UNTIL_REBOOT lpNewFileName NULL, MoveFileEx lpExistingFileName , . lpExistingFileName , , .

+1

All Articles