/// <summary> /// Starts a web server by calling <see cref="IWebServer.RunAsync"/> /// in another thread. /// </summary> /// <param name="this">The <see cref="IWebServer"/> on which this method is called.</param> /// <param name="cancellationToken">A <see cref="CancellationToken"/> used to stop the web server.</param> /// <exception cref="NullReferenceException"><paramref name="this"/> is <see langword="null"/>.</exception> /// <exception cref="InvalidOperationException">The web server has already been started.</exception> public static void Start(this IWebServer @this, CancellationToken cancellationToken = default) { #pragma warning disable CS4014 // The call is not awaited - it is expected to run in parallel. Task.Run(() => @this.RunAsync(cancellationToken)); #pragma warning restore CS4014 while (@this.State < WebServerState.Listening) { Task.Delay(1, cancellationToken).Await(); } }
public void Init() { WebServerUrl = Resources.GetServerAddress(); WebServerInstance = _useTestWebServer ? (IWebServer) new TestWebServer(_routeStrategy) : new WebServer(WebServerUrl, _routeStrategy); _builder(WebServerInstance); WebServerInstance.RunAsync(); }
public void Start() { if (webServer != null) { throw new InvalidOperationException("WebServer is already started!"); } webServer = WebServer .Create(url) .WithStaticFolderAt(htmlPath); Task.Run(() => webServer.RunAsync()); }
public Task StartAsync <TContext>(IHttpApplication <TContext> application, CancellationToken cancellationToken) { // Setup handler module _aspNetModule = new AspNetModule(new HttpApplicationWrapper <TContext>(application), Features); // Setup web server _webServer = new WebServer(_serverAddresses.Addresses.Select(x => $"{x}/").ToArray()); // TODO: Fix //_webServer.Modules.Add(_aspNetModule); // Start listener _webServer.RunAsync(cancellationToken); return(Task.CompletedTask); }
/// <summary> /// Starts this instance. /// </summary> public void Start() { try { lock (_locker) //prevent stop being called before start finishes { _cancelToken = new CancellationTokenSource(); Log.Logger.Information($"Starting web server at [{_config.HostAddress}]..."); _server = CreateWebServer(new[] { _config.HostAddress }); _webServerTask = _server.RunAsync(_cancelToken.Token); Log.Logger.Information("Web server started"); } } catch (Exception error) { Log.Logger.Fatal($"A fatal error has occured while starting {error}"); } }