回答編集履歴
4
orz
test
CHANGED
@@ -59,7 +59,7 @@
|
|
59
59
|
var p = parameters[i];
|
60
60
|
if (p.ParameterType.IsByRef && args[i] is Control control) {
|
61
61
|
var proxy = new ControlProxy(control);
|
62
|
-
args[
|
62
|
+
args[i] = proxy.GetTransparentProxy();
|
63
63
|
}
|
64
64
|
}
|
65
65
|
return result;
|
3
値を返すとき、コントロールの代わりに透過プロキシを返す必要がある
test
CHANGED
@@ -19,17 +19,16 @@
|
|
19
19
|
public static class ControlUtil
|
20
20
|
{
|
21
21
|
public static T CreateProxy<T>(T target) where T : Control {
|
22
|
-
var proxy = new
|
22
|
+
var proxy = new ControlProxy(target);
|
23
23
|
return (T)proxy.GetTransparentProxy();
|
24
24
|
}
|
25
25
|
|
26
|
-
private class
|
26
|
+
private class ControlProxy: RealProxy
|
27
|
-
where T : Control
|
28
27
|
{
|
29
|
-
|
28
|
+
Control _Instance;
|
30
29
|
|
31
|
-
public
|
30
|
+
public ControlProxy(Control target)
|
32
|
-
: base(type
|
31
|
+
: base(target.GetType()) {
|
33
32
|
_Instance = target;
|
34
33
|
}
|
35
34
|
|
@@ -54,7 +53,16 @@
|
|
54
53
|
Func<MethodInfo, object[], object> d = Invoke;
|
55
54
|
return _Instance.Invoke(d, mi, args);
|
56
55
|
} else {
|
57
|
-
ret
|
56
|
+
var result = mi.Invoke(_Instance, args);
|
57
|
+
var parameters = mi.GetParameters();
|
58
|
+
for (int i = 0; i < parameters.Length; i++) {
|
59
|
+
var p = parameters[i];
|
60
|
+
if (p.ParameterType.IsByRef && args[i] is Control control) {
|
61
|
+
var proxy = new ControlProxy(control);
|
62
|
+
args[args.Length - 1] = proxy.GetTransparentProxy();
|
63
|
+
}
|
64
|
+
}
|
65
|
+
return result;
|
58
66
|
}
|
59
67
|
}
|
60
68
|
}
|
@@ -72,7 +80,6 @@
|
|
72
80
|
{
|
73
81
|
public Form1() {
|
74
82
|
InitializeComponent();
|
75
|
-
CheckForIllegalCrossThreadCalls = false;
|
76
83
|
}
|
77
84
|
|
78
85
|
private void button1_Click(object sender, EventArgs e) {
|
2
元に戻す
test
CHANGED
@@ -72,6 +72,7 @@
|
|
72
72
|
{
|
73
73
|
public Form1() {
|
74
74
|
InitializeComponent();
|
75
|
+
CheckForIllegalCrossThreadCalls = false;
|
75
76
|
}
|
76
77
|
|
77
78
|
private void button1_Click(object sender, EventArgs e) {
|
1
透過プロキシを使うなら CheckForIllegalCrossThreadCalls を False にする必要はない
test
CHANGED
@@ -72,7 +72,6 @@
|
|
72
72
|
{
|
73
73
|
public Form1() {
|
74
74
|
InitializeComponent();
|
75
|
-
Control.CheckForIllegalCrossThreadCalls = false;
|
76
75
|
}
|
77
76
|
|
78
77
|
private void button1_Click(object sender, EventArgs e) {
|