You should be able to use an anonymous method or lambda to provide full static checking:
Thread FirstThread = new Thread(() => Fun1(5, 12));
or if you want to do something with the result:
Thread FirstThread = new Thread(() => {
int i = Fun1(5, 12);
// do something with i
});
but note that this "do something" still runs in the context of the new thread (but with access to the other variables in the outer method (Main
) courtesy of "captured variables").
If you have C# 2.0 (and not above), then:
Thread FirstThread = new Thread((ThreadStart)delegate { Fun1(5, 12); });
and
Thread FirstThread = new Thread((ThreadStart)delegate {
int i = Fun1(5, 12);
// do something with i
});
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…