forked from dotnet/java-interop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
56 lines (54 loc) · 1.74 KB
/
Program.cs
File metadata and controls
56 lines (54 loc) · 1.74 KB
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
46
47
48
49
50
51
52
53
54
55
56
using System;
using System.Threading;
using Java.Interop;
namespace Hello
{
class MainClass
{
public static unsafe void Main (string[] args)
{
Console.WriteLine ("Hello World!");
try {
var ignore = JniRuntime.CurrentRuntime;
} catch (InvalidOperationException e) {
Console.WriteLine (e);
}
foreach (var h in JniRuntime.GetAvailableInvocationPointers ()) {
Console.WriteLine ("PRE: GetCreatedJavaVMHandles: {0}", h);
}
Console.WriteLine ("Part 2!");
using (var vm = new JreRuntimeOptions ().CreateJreVM ()) {
Console.WriteLine ("# JniEnvironment.EnvironmentPointer={0}", JniEnvironment.EnvironmentPointer);
Console.WriteLine ("vm.SafeHandle={0}", vm.InvocationPointer);
var t = new JniType ("java/lang/Object");
var c = t.GetConstructor ("()V");
var o = t.NewObject (c, null);
var m = t.GetInstanceMethod ("hashCode", "()I");
int i = JniEnvironment.InstanceMethods.CallIntMethod (o, m);
Console.WriteLine ("java.lang.Object={0}", o);
Console.WriteLine ("hashcode={0}", i);
JniObjectReference.Dispose (ref o);
t.Dispose ();
// var o = JniTypes.FindClass ("java/lang/Object");
/*
var waitForCreation = new CountdownEvent (1);
var exitThread = new CountdownEvent (1);
var t = new Thread (() => {
var vm2 = new JavaVMBuilder ().CreateJavaVM ();
waitForCreation.Signal ();
exitThread.Wait ();
});
t.Start ();
waitForCreation.Wait ();
*/
foreach (var h in JniRuntime.GetAvailableInvocationPointers ()) {
Console.WriteLine ("WITHIN: GetCreatedJavaVMs: {0}", h);
}
// exitThread.Signal ();
}
foreach (var h in JniRuntime.GetAvailableInvocationPointers ()) {
Console.WriteLine ("POST: GetCreatedJavaVMs: {0}", h);
}
}
}
}