假設我有這樣的:復位和處置觀察到的用戶,無擴展
public class UploadDicomSet
{
public UploadDicomSet()
{
var cachCleanTimer = Observable.Interval(TimeSpan.FromMinutes(2));
cachCleanTimer.Subscribe(CheckUploadSetList);
//Start subscriber
}
void CheckUploadSetList(long interval)
{
//Stop and dispose subscriber
}
public void AddDicomFile(SharedLib.DicomFile dicomFile)
{
//Renew subscriber, call CheckUploadSetList 2 minutes later
}
}
由1- CheckUploadSetList
我想處置或AddDicomFile
完成觀察到
2 - 我想重置它
作爲評論的方法。
UPDATE:
我能做到這一點通過Timer
爲:
public class UploadDicomSet : ImportBaseSet
{
Timer _timer;
public UploadDicomSet()
{
_timer = new Timer(CheckUploadSetList, null, 120000, Timeout.Infinite);
}
void CheckUploadSetList(object state)
{
Logging logging = new Logging(LogFile);
try
{
_timer.Dispose(); //Stop the subscription
//dispose everything
}
catch (Exception exp)
{
logging.Log(ErrorCode.Error, "CheckUploadSetList() failed..., EXP:{0}", exp.ToString());
}
}
public void AddDicomFile(SharedLib.DicomFile dicomFile)
{
_timer.Change(120000, Timeout.Infinite);
}
}
在此先感謝。
有人能告訴我爲什麼下投票? – Aria
他們幾乎從來沒有這樣做,可悲的是 –