public void Dispose() { lock (_subscriptions) { _subscriptions.Clear(); } _enqueueSynchronizationContext.Dispose(); }
/// <summary>Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.</summary> public void Dispose() { cancellationTokenSource.Cancel(); videoFrameRenderer.Dispose(); renderingContext.Dispose(); }
public static async Task <int> Main(string[] args) { // monitoring when the ipc host shuts down var exiting = new ManualResetEventSlim(); var configuration = GetConfiguration(args); if (configuration.Debug) { if (!Debugger.IsAttached) { Debugger.Launch(); } else { Debugger.Break(); } } var taskManager = new TaskManager(); var syncContext = new ThreadSynchronizationContext(taskManager.Token); taskManager.Initialize(syncContext); var environment = new UnityEnvironment("Process Manager") .Initialize(configuration.ProjectPath, configuration.UnityVersion, configuration.UnityApplicationPath, configuration.UnityContentsPath); var host = new RpcHostedServer(configuration) .AddRemoteProxy <IServerNotifications>() .AddRemoteProxy <IProcessNotifications>() .AddLocalTarget <ProcessServer.Implementation>() .AddLocalScoped <ProcessRunner.Implementation>() ; host.Stopping(s => { s.GetService <ProcessRunner>().Shutdown(); s.GetService <ProcessServer>().Shutdown(); exiting.Set(); }) .ClientConnecting(s => { // keep track of clients so we can broadcast notifications to them s.GetService <ProcessServer>().ClientConnecting(s.GetRequestContext()); }) .ClientDisconnecting((s, disconnected) => { s.GetService <ProcessRunner>().ClientDisconnecting(s.GetRequestContext()); s.GetService <ProcessServer>().ClientDisconnecting(s.GetRequestContext()); }); // set up a logger var logLevelSwitch = new LoggingLevelSwitch { MinimumLevel = LogEventLevel.Debug }; host.UseSerilog((context, config) => config.MinimumLevel.ControlledBy(logLevelSwitch) .MinimumLevel.Override("Microsoft", LogEventLevel.Information) .Enrich.FromLogContext() .WriteTo.Console()); host.ConfigureServices(services => { // register the log switch so it can be retrieved and changed by any code services.AddSingleton(logLevelSwitch); // make the configuration available to everyone services.AddSingleton(configuration); services.AddSingleton <ITaskManager>(taskManager); services.AddSingleton <IEnvironment>(environment); services.AddSingleton <IProcessEnvironment>(s => s.GetService <IProcessManager>().DefaultProcessEnvironment); services.AddSingleton <IProcessManager, ProcessManager>(); services.AddSingleton <ProcessRunner>(); services.AddSingleton <ProcessServer>(); }); host.UseConsoleLifetime(); await host.Start(); Console.WriteLine($"Port:{host.Rpc.Configuration.Port}"); try { await host.Run(); } catch {} // wait until all stop events have completed exiting.Wait(); syncContext.Dispose(); return(0); }