/// <summary> /// The constructor which takes all the DI objects /// </summary> /// <param name="logger">ILogger</param> /// <param name="applicationLifetime">IApplicationLifetime</param> /// <param name="serviceProvider">IServiceProvider</param> /// <param name="winFormsContext">IWinFormsContext</param> public WinFormsHostedService(ILogger <WinFormsHostedService> logger, IApplicationLifetime applicationLifetime, IServiceProvider serviceProvider, IWinFormsContext winFormsContext) { _logger = logger; _applicationLifetime = applicationLifetime; _serviceProvider = serviceProvider; _winFormsContext = winFormsContext; }
/// <summary> /// Helper method to retrieve the IWinFormsContext /// </summary> /// <param name="properties">IDictionary</param> /// <param name="winFormsContext">IWinFormsContext out value</param> /// <returns>bool if there was already an IWinFormsContext</returns> private static bool TryRetrieveWinFormsContext(this IDictionary <object, object> properties, out IWinFormsContext winFormsContext) { if (properties.TryGetValue(WinFormsContextKey, out var winFormsContextAsObject)) { winFormsContext = winFormsContextAsObject as IWinFormsContext; return(true); } winFormsContext = new WinFormsContext(); properties[WinFormsContextKey] = winFormsContext; return(false); }
/// <summary> /// Constructor which is called from the IWinFormsContext /// </summary> /// <param name="winFormsContext">IWinFormsContext</param> public WinFormsThread(IWinFormsContext winFormsContext) { _winFormsContext = winFormsContext; // Create a thread which runs WPF var newWpfThread = new Thread(WinFormsThreadStart) { IsBackground = true }; // Set the apartment state newWpfThread.SetApartmentState(ApartmentState.STA); // Start the new WPF thread newWpfThread.Start(); }
/// <summary> /// The constructor which takes all the DI objects /// </summary> /// <param name="logger">ILogger</param> /// <param name="winFormsThread">WinFormsThread</param> /// <param name="winFormsContext">IWinFormsContext</param> public WinFormsHostedService(ILogger <WinFormsHostedService> logger, WinFormsThread winFormsThread, IWinFormsContext winFormsContext) { _logger = logger; _winFormsThread = winFormsThread; _winFormsContext = winFormsContext; }
/// <summary> /// The constructor which takes all the DI objects /// </summary> /// <param name="logger">ILogger</param> /// <param name="serviceProvider">IServiceProvider</param> /// <param name="winFormsContext">IWinFormsContext</param> public WinFormsHostedService(ILogger <WinFormsHostedService> logger, IServiceProvider serviceProvider, IWinFormsContext winFormsContext) { _logger = logger; _serviceProvider = serviceProvider; _winFormsContext = winFormsContext; }