1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
using System;
using System.IO;
namespace ShadowCopy
{
class Program
{
[LoaderOptimization(LoaderOptimization.MultiDomainHost)]
[STAThread]
static void Main(string[] args)
{
// Shadow-Copying ermöglichen:
string environmentPath = Environment.CurrentDirectory;
string cachePath = Path.Combine(
environmentPath,
"__cache");
string configFile = Path.Combine(
environmentPath,
"Anwendung.exe.config");
string assembly = Path.Combine(
environmentPath,
"Anwendung.exe");
// Anwendungsdomänen-Setup ertellen:
AppDomainSetup setup = new AppDomainSetup();
setup.ApplicationName = "Anwendung";
setup.ShadowCopyFiles = "true";
setup.CachePath = cachePath;
setup.ConfigurationFile = configFile;
// Anwendungsdomäne erstellen:
AppDomain domain = AppDomain.CreateDomain(
"Beispiel",
AppDomain.CurrentDomain.Evidence,
setup);
// Anwendung starten:
domain.ExecuteAssembly(assembly);
// Cache bereinigen:
AppDomain.Unload(domain);
Directory.Delete(cachePath, true);
}
}
}
|