public void Close() { EventClose?.Invoke(new IOEventResult(this, IOEventType.Close, AegisResult.Ok)); AegisTask.SafeAction(() => { PipeStream?.Close(); PipeStream = null; }); }
public void Listen() { Reset(); var stream = PipeStream as NamedPipeServerStream; if (stream == null) { return; } stream.BeginWaitForConnection((asyncResult) => { AegisTask.SafeAction(() => { stream.EndWaitForConnection(asyncResult); EventAccept?.Invoke(new IOEventResult(this, IOEventType.Accept, AegisResult.Ok)); WaitForReceive(); }); }, null); }
public static void Initialize() { string[] args = Environment.GetCommandLineArgs(); // 프레임워크 초기화 { SpinWorker.Initialize(); _stopRunningEvent = new EventWaitHandle(false, EventResetMode.ManualReset); _releaseEvent = new EventWaitHandle(false, EventResetMode.ManualReset); Logger.Info(LogMask.Aegis, "Aegis Framework({0})", AegisVersion.ToString(3)); } AegisTask.Run(() => { // 컨텐츠 초기화 (UI 모드) if (Environment.UserInteractive) { AegisTask.SafeAction(() => { if (Initialized == null || Initialized.Invoke(args) == true) { Running?.Invoke(); } }); AegisTask.SafeAction(() => { Finalizing?.Invoke(CloseReason.Close); }); } // 컨텐츠 초기화 (서비스 모드) else { ServiceMain.Instance.EventStart = () => { AegisTask.SafeAction(() => { if (Initialized == null || Initialized?.Invoke(System.Environment.GetCommandLineArgs()) == true) { // Running이 설정된 경우에는 Running이 반환되기를 대기하고, 반환된 후 종료처리 진행 if (Running != null) { (new Thread(() => { AegisTask.SafeAction(() => { Running.Invoke(); }); ServiceMain.Instance.Stop(); })).Start(); } } }); }; ServiceMain.Instance.EventStop = () => { AegisTask.SafeAction(() => { Finalizing?.Invoke(CloseReason.ServiceStop); }); }; ServiceMain.Instance.EventShutDown = () => { AegisTask.SafeAction(() => { Finalizing?.Invoke(CloseReason.ShutDown); }); }; ServiceMain.Instance.Run(); } _stopRunningEvent.Set(); }); AegisTask.Run(() => { WaitForRunning(); // 프레임워크 종료 Calculate.IntervalTimer.DisposeAll(); NamedThread.DisposeAll(); NamedObjectManager.Clear(); SpinWorker.Release(); Logger.Info(LogMask.Aegis, "Aegis Framework finalized."); Logger.RemoveAll(); AegisTask.SafeAction(() => { Finalized?.Invoke(); }); Initialized = null; Finalizing = null; Finalized = null; Running = null; _releaseEvent.Set(); }); }