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
, - - , - DLL AppDomain , . AppDomain, DLL .
, exe, AppDomain. , stub exe , , AppDomain, .
. DLL , DLL , , . , . , AppDomain, .
Unwrap , . - "" , command.run, appdomain. , , .
, , .
, . , temp, (System.Diagnostics.Process.Start()), , : " ". exe.
exe , , , . . exe .
- . .
MOVEFILE_DELAY_UNTIL_REBOOT . , , , , ; DLL explorer.exe DLL ..
MOVEFILE_DELAY_UNTIL_REBOOT
MoveFileEx MSDN;
lpNewFileName [in, ] .. , MOVEFILE_COPY_ALLOWED dwFlags..dwFlags MOVEFILE_DELAY_UNTIL_REBOOT lpNewFileName NULL, MoveFileEx lpExistingFileName , . lpExistingFileName , , .
lpNewFileName [in, ] .
. , MOVEFILE_COPY_ALLOWED dwFlags.
MOVEFILE_COPY_ALLOWED
.
dwFlags MOVEFILE_DELAY_UNTIL_REBOOT lpNewFileName NULL, MoveFileEx lpExistingFileName , . lpExistingFileName , , .