public NFKProcess() { sw = new Stopwatch(); Intro = new FormIntro(); // this form is for escape hook (application form must be running) StubForm = new FormAutoClose() { StartPosition = FormStartPosition.Manual, Left = -100, Top = -100, Height = 0, Width = 0 }; StubForm.Shown += (object _sender, EventArgs _e) => { if (StubForm != null) { StubForm.Hide(); } }; // close nfk by escape kbh = new LowLevelKeyboardHook(); kbh.OnKeyPressed += (object _sender, System.Windows.Forms.Keys _e) => { if (_e == Keys.Escape) { Dispose(); } }; kbh.HookKeyboard(); }
private bool disposedValue = false; // To detect redundant calls protected virtual void Dispose(bool disposing) { if (!disposedValue) { if (disposing) { // dispose managed state (managed objects). } // TODO: free unmanaged resources (unmanaged objects) and override a finalizer below. // TODO: set large fields to null. try { if (kbh != null) { kbh.UnHookKeyboard(); } if (p != null) { p.Kill(); p.Close(); p = null; } if (Intro != null) { // close intro Intro.CloseFlag = true; } StubForm.CloseFlag = true; StubForm = null; // delete temp exe // FIXME: it may be not deleted if there are two instances of the program are running File.Delete(Path.Combine(NFKHelper.GetGameWorkingDir(), NFKHelper.GAME_EXE_TEMP)); } catch (Exception e) { } disposedValue = true; } }