123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- namespace SAGA.DotNetUtils
- {
- using System;
- using System.Threading;
- public class ThreadTimeoutCallback : TimeoutCallback
- {
- private bool disposeable;
- private object ThisSysnObject;
- private Timer timer;
- public ThreadTimeoutCallback(TimeoutCallbackHandler handler, int timeout, object[] values) : base(handler, timeout, values)
- {
- this.ThisSysnObject = new object();
- }
- public override void DisposeCoerce()
- {
- lock (this.ThisSysnObject)
- {
- this.disposeable = true;
- this.StopTimer();
- }
- }
- protected override bool StartTimer()
- {
- lock (this.ThisSysnObject)
- {
- if (this.timer == null)
- {
- this.timer = new Timer(new TimerCallback(this.TimerCallbackHandler), null, Math.Min(1, base.timeout), 0x124f80);
- return true;
- }
- return false;
- }
- }
- protected override bool StopTimer()
- {
- if ((this.timer == null) || !this.Disposable)
- {
- return false;
- }
- try
- {
- this.timer.Dispose();
- }
- catch
- {
- }
- this.timer = null;
- return true;
- }
- private void TimerCallbackHandler(object state)
- {
- lock (this.ThisSysnObject)
- {
- if (this.timer != null)
- {
- try
- {
- if (base.handler != null)
- {
- base.handler(base.values);
- }
- }
- catch
- {
- }
- }
- this.disposeable = true;
- this.StopTimer();
- }
- }
- public override bool Disposable
- {
- get
- {
- return this.disposeable;
- }
- }
- }
- }
|