I handle catching the ctrl-c a little different then in the C# plugin example.
Instead of PInvoking the native SetConsoleCtrlHandler() function I add a handler to the managed Console.CancelKeyPress event.
The important item in the code below was the e.Cancel must be set true to keep the app running until the cancel exception is thrown by the underlying ftp library that I use.
By default, the Cancel property is false, which causes program execution to terminate when the event handler exits.
After fixing that bug, I no longer get force killed by ffastrans.
Code: Select all
Console.CancelKeyPress += Console_CancelKeyPress;
private static void Console_CancelKeyPress(object sender, ConsoleCancelEventArgs e)
{
//user on ffastrans cancelled the job, we get a CTRL_C_EVENT
//do whats needed to teardown your process (e.g. send cancel job to external transcoder api etc...)
// set e.Cancel to true to keep application running until the cancelation has completed.
// This will happen when the cancelled exception is thrown by ftp client which gracefully terminates the application.
e.Cancel = true;
Console.WriteLine("Canceling...");
//Cancel the token source to signal async download to cancel.
cts.Cancel();
}
// At the end of the cancel exception handling where I do some cleanup, I do the following to end gracefully.
EndProgram("Canceled", 0);