-
Notifications
You must be signed in to change notification settings - Fork 0
/
Loader.cs
63 lines (58 loc) · 1.8 KB
/
Loader.cs
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
57
58
59
60
61
62
63
using System;
using Microsoft.SPOT;
using System.Reflection;
using System.IO;
using System.Threading;
namespace Redecode.Archimede
{
public class Loader
{
public static Assembly LoadAssembly(string file)
{
Assembly assembly = null;
try
{
using (FileStream assmfile = new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.None))
{
byte[] assmbytes = new byte[assmfile.Length];
assmfile.Read(assmbytes, 0, (int)assmfile.Length);
//bool loaded = false;
Thread tConnect = new Thread(() =>
{
try
{
assembly = Assembly.Load(assmbytes);
//loaded = true;
}
catch
{
}
});
tConnect.Start();
int millsThread = 0;
while (tConnect.IsAlive && millsThread < 10)
{
Thread.Sleep(10);
millsThread += 10;
}
if (tConnect.IsAlive)
{
tConnect.Abort();
}
tConnect = null;
assmfile.Close();
}
}
catch (Exception ex)
{
}
return assembly;
}
public static void CallMain(string className)
{
Type magicType = Type.GetType(className);
MethodInfo magicMethod = magicType.GetMethod("Main");
magicMethod.Invoke(null, null);
}
}
}