0

I have an application that should send a log when it exits to a cloud function. This means it can take a long time to get an answer if I'm unlucky (sometimes minutes!). I don't want my application to stay in the background for that long so I just want to fire and forget the log message. I don't need 100% guarantees, but as close as possible is of course nice.

What's the best method to achieve this? I've read the answers to this question, but it's aimed at ASP.Net applications. Is this still applicable for a WPF application that exits and disappears, potentially before there will ever be an answer from the server, or are there better ways in this case?

Thanks!

mottosson
  • 3,283
  • 4
  • 35
  • 73
  • If *anything* is quick at disapearing, it is the ASP.Net page/request. This is their lifecycle: https://learn.microsoft.com/en-us/previous-versions/ms178472(v=vs.140) | Pages are supposed to be created, process, send to the user and be dropped out of memory ASAP. And this applies to all web technology. Compared to that, a WPF application is a tectonic movement. | Multitasking usually has to be done on the client side - it is the only place where code can life long enough, to get an answer. – Christopher Nov 15 '19 at 13:28
  • I follow Maxim 26. "Fire and Forget" is fine, provided you never actually forget. | Swallowing exceptions is one cardinal sin of exception handling. Normally you have to write a very bad catch for it. But Multitasking? Fire and Forget tasks? Those are *notorious* for swallowing exceptions. You would have to stop application closure, until all started tasks/threads a finished. And of obvious reasons, you should have a way to abort them. | It is not as critical on application closure - the application will end either way. But I still do not like it. – Christopher Nov 15 '19 at 13:32

0 Answers0