具有动态功能的线程/定时器,具有可变数量和参数类型 [英] Thread/timer with dynamic function with variable number and type of parameters
问题描述
我需要创建ThReads / Timers但是要在标准化的功能中。 ThReadFunction可以具有可变数量和类型的参数。与Elapsed和计时器相同。谢谢你
System.Threading.Thread Fcn_ThReadNew(动态ThReadFuncion)
{System.Threading.Thread MyThRead = new System.Threading.Thread (ThReadFuncion);
$
返回MyThRead;
}
$
私有静态void Fcn_TimerElapsed(动态MyElapsed)
{System.Timers.Timer MyTimer = new System.Timers.Timer();
MyTimer.Elapsed + = MyElapsed;
}
考虑行动:
private static void Fcn_TimerElapsed(Action MyElapsed)
; {
System.Timers.Timer MyTimer = new System.Timers.Timer();
<跨度>&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; MyTimer.Elapsed + =(s,a)=> MyElapsed();
}
当你调用它时,请使用短lambda使用参数调用函数的表达式,例如:
Fcn_TimerElapsed(()=> MyFunction(a,b,c,d));
&NBSP; 跨度>
I need to create ThReads/Timers but in a function to standardize. ThReadFunction may have variable number and type of Parameters. Same with Elapsed and timer. Thank you
System.Threading.Thread Fcn_ThReadNew(dynamic ThReadFuncion)
{ System.Threading.Thread MyThRead = new System.Threading.Thread(ThReadFuncion);
return MyThRead;
}
private static void Fcn_TimerElapsed(dynamic MyElapsed)
{ System.Timers.Timer MyTimer = new System.Timers.Timer();
MyTimer.Elapsed += MyElapsed;
}
Consider Action:
private static void Fcn_TimerElapsed(Action MyElapsed)
{
System.Timers.Timer MyTimer = new System.Timers.Timer();
MyTimer.Elapsed += (s,a) => MyElapsed();
}
When you call it, use a short lambda expression that invokes your function with arguments, for example:
Fcn_TimerElapsed( ( ) => MyFunction(a, b, c, d) );
这篇关于具有动态功能的线程/定时器,具有可变数量和参数类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!