public void StartAsync()
        {
            if (isRunning)
            {
                return;
            }

            isRunning   = true;
            tokenSource = new CancellationTokenSource();

            Task.Factory.StartNew(() =>
            {
                var address = $"http://{componentConfiguration.Host}:{componentConfiguration.Port}";

                var options = new StartOptions(address)
                {
                    ServerFactory = "Microsoft.Owin.Host.HttpListener"
                };

                using (WebApp.Start(options, appBuilder => { startupConfiguration.Configuration(appBuilder); }))
                {
                    Console.WriteLine($"Started {DateTime.Now.ToString(CultureInfo.InvariantCulture)}");
                    while (true)
                    {
                        if (!tokenSource.Token.IsCancellationRequested)
                        {
                            continue;
                        }
                        isRunning = false;
                        return;
                    }
                }
            }, tokenSource.Token);
        }
Beispiel #2
0
        public void Start()
        {
            try
            {
                var address = $"{(_configuration.UseInsecureHttp ? "http" : "https")}://{_configuration.HostName}:{_configuration.Port}";
                _logger?.Information("Listening on {ListeningAddress}", address);

                _host = WebApp.Start(address, app => _startup.Configuration(app));
            }
            catch (Exception ex)
            {
                _logger?.Error(ex, "Error during start of the RelayServer listener");
                throw;
            }
        }