mirror of
https://github.com/fergalmoran/DnsServer.git
synced 2026-01-04 15:55:32 +00:00
implementation change done to handle app process exit correctly on .net core.
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
Technitium DNS Server
|
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
|
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
|
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("Technitium DNS Server was started successfully.");
|
||||||
Console.WriteLine("Using config folder: " + service.ConfigFolder);
|
Console.WriteLine("Using config folder: " + service.ConfigFolder);
|
||||||
Console.WriteLine("");
|
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("");
|
||||||
|
Console.WriteLine("Press [CTRL + C] to stop...");
|
||||||
|
|
||||||
if (Console.IsInputRedirected)
|
Thread main = Thread.CurrentThread;
|
||||||
{
|
|
||||||
//app running as background service
|
|
||||||
Thread.Sleep(Timeout.Infinite);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Console.WriteLine("Press [CTRL + X] to stop...");
|
|
||||||
|
|
||||||
while (true)
|
Console.CancelKeyPress += delegate (object sender, ConsoleCancelEventArgs e)
|
||||||
|
{
|
||||||
|
e.Cancel = true;
|
||||||
|
main.Interrupt();
|
||||||
|
};
|
||||||
|
|
||||||
|
AppDomain.CurrentDomain.ProcessExit += delegate (object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (service != null)
|
||||||
{
|
{
|
||||||
ConsoleKeyInfo key = Console.ReadKey(true);
|
Console.WriteLine("");
|
||||||
|
Console.WriteLine("Technitium DNS Server is stopping...");
|
||||||
if (key.Modifiers == ConsoleModifiers.Control && key.Key == ConsoleKey.X)
|
service.Dispose();
|
||||||
break;
|
service = null;
|
||||||
|
Console.WriteLine("Technitium DNS Server was stopped successfully.");
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
|
Thread.Sleep(Timeout.Infinite);
|
||||||
}
|
}
|
||||||
|
catch (ThreadInterruptedException)
|
||||||
|
{ }
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Console.WriteLine(ex.ToString());
|
Console.WriteLine(ex.ToString());
|
||||||
@@ -71,8 +78,10 @@ namespace DnsServerApp
|
|||||||
{
|
{
|
||||||
if (service != null)
|
if (service != null)
|
||||||
{
|
{
|
||||||
|
Console.WriteLine("");
|
||||||
Console.WriteLine("Technitium DNS Server is stopping...");
|
Console.WriteLine("Technitium DNS Server is stopping...");
|
||||||
service.Dispose();
|
service.Dispose();
|
||||||
|
service = null;
|
||||||
Console.WriteLine("Technitium DNS Server was stopped successfully.");
|
Console.WriteLine("Technitium DNS Server was stopped successfully.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
Technitium DNS Server
|
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
|
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
|
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("Technitium DNS Server was started successfully.");
|
||||||
Console.WriteLine("Using config folder: " + service.ConfigFolder);
|
Console.WriteLine("Using config folder: " + service.ConfigFolder);
|
||||||
Console.WriteLine("");
|
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("");
|
||||||
|
Console.WriteLine("Press [CTRL + C] to stop...");
|
||||||
|
|
||||||
if (Console.IsInputRedirected)
|
Thread main = Thread.CurrentThread;
|
||||||
{
|
|
||||||
//app running as background service
|
|
||||||
Thread.Sleep(Timeout.Infinite);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Console.WriteLine("Press [CTRL + X] to stop...");
|
|
||||||
|
|
||||||
while (true)
|
Console.CancelKeyPress += delegate (object sender, ConsoleCancelEventArgs e)
|
||||||
|
{
|
||||||
|
e.Cancel = true;
|
||||||
|
main.Interrupt();
|
||||||
|
};
|
||||||
|
|
||||||
|
AppDomain.CurrentDomain.ProcessExit += delegate (object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (service != null)
|
||||||
{
|
{
|
||||||
ConsoleKeyInfo key = Console.ReadKey(true);
|
Console.WriteLine("");
|
||||||
|
Console.WriteLine("Technitium DNS Server is stopping...");
|
||||||
if (key.Modifiers == ConsoleModifiers.Control && key.Key == ConsoleKey.X)
|
service.Dispose();
|
||||||
break;
|
service = null;
|
||||||
|
Console.WriteLine("Technitium DNS Server was stopped successfully.");
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
|
Thread.Sleep(Timeout.Infinite);
|
||||||
}
|
}
|
||||||
|
catch (ThreadInterruptedException)
|
||||||
|
{ }
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Console.WriteLine(ex.ToString());
|
Console.WriteLine(ex.ToString());
|
||||||
@@ -71,8 +78,10 @@ namespace DnsServerApp
|
|||||||
{
|
{
|
||||||
if (service != null)
|
if (service != null)
|
||||||
{
|
{
|
||||||
|
Console.WriteLine("");
|
||||||
Console.WriteLine("Technitium DNS Server is stopping...");
|
Console.WriteLine("Technitium DNS Server is stopping...");
|
||||||
service.Dispose();
|
service.Dispose();
|
||||||
|
service = null;
|
||||||
Console.WriteLine("Technitium DNS Server was stopped successfully.");
|
Console.WriteLine("Technitium DNS Server was stopped successfully.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user