Page 2 of 2

Re: Custom Processor

Posted: Thu Oct 26, 2023 5:31 pm
by whtghst1
Thanks for that. The cancellation should have been completed within that time frame. I found the source of my problem.

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);
whtghst1

Re: Custom Processor

Posted: Thu Oct 26, 2023 6:56 pm
by emcodem
Hehe i was not even aware that a managed version of the sigint handler exists, maybe i spent too much time with C++ :D Great stuff, thanks for it!

Re: Custom Processor

Posted: Thu Oct 26, 2023 7:04 pm
by whtghst1
I understand that. I use native functions a lot as well.
I have entire library of native functions that I use PInvoking with. i.e. FileCopyEx because there is no managed version of copy/move with progress.