我有一个问题,那就是使用C#的Timers.Timer
类.考虑到以下大体轮廓:
1-回调是否在对象本身的上下文中运行,这样我就可以只使用成员变量(不像C++那样,您必须传递对象指针)?
class A {
Timer m_Timer;
int m_JustForShow;
public void TimerHandler(Object stateinfo) {
// is this right?
string id=(string) stateinfo;
// use id to check if action has completed and if not
// we cancel it.
if (m_JustForShow==1) {
// Is this running under the objects context and I can just do this?
}
}
public void MyEventNotification(in MyEventInfo ei)
{
if (ei.State!=MyEventState.Completed) {
m_Timer=new Timer(TimerHandler, new ei.StringID, 1000, Timeout.Infinite);
}
}
}