IKVM11  11
Java SE 11 Virtual Machine for .NET
Loading...
Searching...
No Matches
ExecutionContext.NetFramework.cs
Go to the documentation of this file.
1#if NETFRAMEWORK
2
3using System;
4using System.Threading;
5using System.Threading.Tasks;
6
8{
9
10 partial class ExecutionContext
11 {
12
16 class ExecutionContextDispatcher : MarshalByRefObject
17 {
18
19 readonly string[] _args;
20
26 public ExecutionContextDispatcher(string[] args)
27 {
28 _args = args ?? throw new ArgumentNullException(nameof(args));
29 }
30
35 public int Execute()
36 {
37 return Task.Run(() => ImportTool.ExecuteInContext(_args)).GetAwaiter().GetResult();
38 }
39
40 }
41
42 AppDomain appDomain;
43 ExecutionContextDispatcher dispatcher;
44
50 public ExecutionContext(string[] args)
51 {
52 appDomain = AppDomain.CreateDomain(
53 "IkvmImporter",
54 AppDomain.CurrentDomain.Evidence,
55 new AppDomainSetup()
56 {
57 ApplicationBase = AppDomain.CurrentDomain.SetupInformation.ApplicationBase,
58 ConfigurationFile = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile,
59 });
60
61 dispatcher = (ExecutionContextDispatcher)appDomain.CreateInstanceAndUnwrap(
62 typeof(ExecutionContextDispatcher).Assembly.GetName().FullName,
63 typeof(ExecutionContextDispatcher).FullName,
64 false,
65 System.Reflection.BindingFlags.Default,
66 null,
67 [args],
68 null,
69 null);
70 }
71
77 public partial async Task<int> ExecuteAsync(CancellationToken cancellationToken)
78 {
79 return await Task.Run(dispatcher.Execute);
80 }
81
85 public void Dispose()
86 {
87 try
88 {
89 dispatcher = null;
90 if (appDomain != null)
91 AppDomain.Unload(appDomain);
92 }
93 catch
94 {
95 // ignore
96 }
97 finally
98 {
99 appDomain = null;
100 }
101
102 GC.SuppressFinalize(this);
103 }
104
105 }
106
107}
108
109#endif
IKVM.Reflection.Assembly Assembly
partial Task< int > ExecuteAsync(CancellationToken cancellationToken)
Executes the importer logic.