using System;
using System.Threading;

namespace QC.QSPR.Threading;

public class TimeoutEvent : IDisposable
{
	private ManualResetEvent waitHandle = new ManualResetEvent(initialState: false);

	private Timer timeoutTimer;

	public ManualResetEvent WaitHandle => waitHandle;

	protected Timer TimeoutTimer => timeoutTimer;

	public TimeoutEvent(int timeoutMilliseconds)
	{
		TimerCallback callback = delegate
		{
			WaitHandle.Set();
		};
		timeoutTimer = new Timer(callback, null, timeoutMilliseconds, -1);
	}

	public void Dispose()
	{
		TimeoutTimer.Dispose();
	}
}
