implementation change done to handle app process exit correctly on .net core.

This commit is contained in:
Shreyas Zare
2019-01-19 15:14:46 +05:30
parent e751dd3e18
commit 6886b7b53d
2 changed files with 50 additions and 32 deletions

View File

@@ -1,6 +1,6 @@
/*
Technitium DNS Server
Copyright (C) 2018 Shreyas Zare (shreyas@technitium.com)
Copyright (C) 2019 Shreyas Zare (shreyas@technitium.com)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -42,27 +42,34 @@ namespace DnsServerApp
Console.WriteLine("Technitium DNS Server was started successfully.");
Console.WriteLine("Using config folder: " + service.ConfigFolder);
Console.WriteLine("");
Console.WriteLine("Note: Open http://localhost:" + service.WebServicePort + "/ in web browser to access web console.");
Console.WriteLine("Note: Open http://" + Environment.MachineName.ToLower() + ":" + service.WebServicePort + "/ in web browser to access web console.");
Console.WriteLine("");
Console.WriteLine("Press [CTRL + C] to stop...");
if (Console.IsInputRedirected)
Thread main = Thread.CurrentThread;
Console.CancelKeyPress += delegate (object sender, ConsoleCancelEventArgs e)
{
//app running as background service
e.Cancel = true;
main.Interrupt();
};
AppDomain.CurrentDomain.ProcessExit += delegate (object sender, EventArgs e)
{
if (service != null)
{
Console.WriteLine("");
Console.WriteLine("Technitium DNS Server is stopping...");
service.Dispose();
service = null;
Console.WriteLine("Technitium DNS Server was stopped successfully.");
}
};
Thread.Sleep(Timeout.Infinite);
}
else
{
Console.WriteLine("Press [CTRL + X] to stop...");
while (true)
{
ConsoleKeyInfo key = Console.ReadKey(true);
if (key.Modifiers == ConsoleModifiers.Control && key.Key == ConsoleKey.X)
break;
}
}
}
catch (ThreadInterruptedException)
{ }
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
@@ -71,8 +78,10 @@ namespace DnsServerApp
{
if (service != null)
{
Console.WriteLine("");
Console.WriteLine("Technitium DNS Server is stopping...");
service.Dispose();
service = null;
Console.WriteLine("Technitium DNS Server was stopped successfully.");
}
}

View File

@@ -1,6 +1,6 @@
/*
Technitium DNS Server
Copyright (C) 2018 Shreyas Zare (shreyas@technitium.com)
Copyright (C) 2019 Shreyas Zare (shreyas@technitium.com)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -42,27 +42,34 @@ namespace DnsServerApp
Console.WriteLine("Technitium DNS Server was started successfully.");
Console.WriteLine("Using config folder: " + service.ConfigFolder);
Console.WriteLine("");
Console.WriteLine("Note: Open http://localhost:" + service.WebServicePort + "/ in web browser to access web console.");
Console.WriteLine("Note: Open http://" + Environment.MachineName.ToLower() + ":" + service.WebServicePort + "/ in web browser to access web console.");
Console.WriteLine("");
Console.WriteLine("Press [CTRL + C] to stop...");
if (Console.IsInputRedirected)
Thread main = Thread.CurrentThread;
Console.CancelKeyPress += delegate (object sender, ConsoleCancelEventArgs e)
{
//app running as background service
e.Cancel = true;
main.Interrupt();
};
AppDomain.CurrentDomain.ProcessExit += delegate (object sender, EventArgs e)
{
if (service != null)
{
Console.WriteLine("");
Console.WriteLine("Technitium DNS Server is stopping...");
service.Dispose();
service = null;
Console.WriteLine("Technitium DNS Server was stopped successfully.");
}
};
Thread.Sleep(Timeout.Infinite);
}
else
{
Console.WriteLine("Press [CTRL + X] to stop...");
while (true)
{
ConsoleKeyInfo key = Console.ReadKey(true);
if (key.Modifiers == ConsoleModifiers.Control && key.Key == ConsoleKey.X)
break;
}
}
}
catch (ThreadInterruptedException)
{ }
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
@@ -71,8 +78,10 @@ namespace DnsServerApp
{
if (service != null)
{
Console.WriteLine("");
Console.WriteLine("Technitium DNS Server is stopping...");
service.Dispose();
service = null;
Console.WriteLine("Technitium DNS Server was stopped successfully.");
}
}