public virtual void Dispose() { IgnoreUserConfirmationPtr = null; SMProcess.Native.Exited -= OnSMExited; try { SMHookEngine.Instance.CleanupHooks(); } catch (Exception ex) { LogTo.Error(ex, "Failed to cleanup SMHookEngine"); } try { OnSMStoppedEvent?.Invoke(this, new SMProcessArgs(this, SMProcess)); } catch (Exception ex) { LogTo.Error(ex, "An exception occured in one of OnSMStoppedEvent handlers"); } }
// // Collection loading management public async Task <bool> Start( NativeDataCfg nativeDataCfg, StartupCfg startupCfg, SMCollection collection) { try { if (_sm != null) { throw new InvalidOperationException("_sm is already instantiated"); } await LoadConfig(collection, startupCfg); var nativeData = CheckSuperMemoExecutable(nativeDataCfg); _sm = InstantiateSuperMemo(collection, nativeData.SMVersion); // TODO: Move somewhere else _sm.UI.ElementWdw.OnAvailable += OnSuperMemoWindowsAvailable; await _sm.Start(nativeData); // TODO: Ensure opened collection (windows title) matches parameter } catch (Exception ex) { if (ex is SMAException) { LogTo.Warning(ex, "Failed to start SM."); } else { LogTo.Error(ex, "Failed to start SM."); } _sm?.Dispose(); _sm = null; try { if (OnSMStoppedEvent != null) { await OnSMStoppedEvent.InvokeAsync(this, new SMProcessArgs(_sm, null)).ConfigureAwait(true); } } catch (Exception pluginEx) { LogTo.Error(pluginEx, "Exception while notifying plugins OnSMStoppedEvent."); } // TODO: Handle exception return(false); } return(true); }
public async Task OnSMStopped() { _sm = null; if (OnSMStoppedEvent != null) { await OnSMStoppedEvent.InvokeAsync(this, null); } }
public void OnSMStopped() { _sm = null; try { OnSMStoppedEvent?.Invoke(this, null); } catch (Exception ex) { LogTo.Error(ex, "Exception thrown while notifying subscribers of OnSMStoppedEvent. Killing process"); System.Diagnostics.Process.GetCurrentProcess().Kill(); } }
public void OnSMStopped() { _sm = null; OnSMStoppedEvent?.Invoke(this, null); }