How to prevent my Timer from GC collecting before its callback excuted?

后端 未结 6 705
情深已故
情深已故 2021-01-26 06:51

I need to create a bunch of timer as local variable to do something like:

void Foo()
{
    Timer t = new Timer(myTimerCallback,null,1000,Timeout.Infinite);
}
         


        
6条回答
  •  天涯浪人
    2021-01-26 07:32

    Why it's impossible to store them? Maybe you can just remove them from that collection when their work is done?

提交回复
热议问题