Custom Processor

Questions and answers on how to get the most out of FFAStrans
whtghst1
Posts: 11
Joined: Mon Oct 23, 2023 9:27 pm

Re: Custom Processor

Post 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
whtghst1
emcodem
Posts: 1737
Joined: Wed Sep 19, 2018 8:11 am

Re: Custom Processor

Post 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!
emcodem, wrapping since 2009 you got the rhyme?
whtghst1
Posts: 11
Joined: Mon Oct 23, 2023 9:27 pm

Re: Custom Processor

Post 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.
whtghst1
Post Reply