#pragma warning restore IDE0032 public ModuleSupervisor(DirectoryInfo directory, IMetadataReader metadataReader, ILogger <ModuleSupervisor> logger = null) { if (directory == null) { throw new ArgumentNullException(nameof(directory)); } if (metadataReader == null) { throw new ArgumentNullException(nameof(metadataReader)); } Directory = directory; _metadataReader = metadataReader; _logger = logger; // Volatile write op (Is avtually not necessary here, because the CLR enforces thread-safety.) _state = ModuleSupervisorState.Initializing; _metadataLazy = new DisposableAsyncLazy <IModuleMetadata>( factory: LookupMetadataAsync, options: DisposableAsyncLazyOptions.Autostart | DisposableAsyncLazyOptions.ExecuteOnCallingThread | DisposableAsyncLazyOptions.RetryOnFailure); _supervisorProcess = new AsyncProcess(SupervisorProcessRoutine, start: true); _disposeHelper = new AsyncDisposeHelper(DisposeInternalAsync); }
private void SetState(ModuleSupervisorState state) { Assert(state >= ModuleSupervisorState.Initializing && state <= ModuleSupervisorState.Shutdown); _state = state; // Volatile write op. StateChanged?.Invoke(this, state); }