Home » c# » c# – Forcing action right before application termination-Exceptionshub

c# – Forcing action right before application termination-Exceptionshub

Posted by: admin February 24, 2020 Leave a comment


I have 2 libraries.

The first one downloads some web pages and stores them in more “parsable” way to some files on disc.

The other relies on the files and therefore it needs some sort of verification that all the files were downloaded and processed correctly.

I couldn’t figure out any other solution than the first library creating something like setup.txt where it would append messages such as $"Exception {e.GetType()} - {pathToDirectoryWithCorruptedFiles}" or $"Success - {pathToDirectoryWithCorrectFiles}".

I don’t think this is the correct way, because after exceptions like StackOverFlowException or OutOfMemoryException and after termination with Ctrl + C the program is terminated and so there is no time to do something.

Is there any way of writing something or storing some information after these exceptions of after Ctrl + C ? Thank you for your answers.

How to&Answers:

If I understand correctly – one application downloads the file, and the second processes it. You need to notify the second application that the file download was completed successfully. Correct me if I’m wrong. I think it is better to use a message broker to send a message from the first application to the secondю This message will notify the second one that the work is completed without error and the second application can start working. Rabbitmq or Kafka should do the trick.
Or if there are exactly libraries – you can use events to notify the second library that file was downloaded successfully.