0

I have the following audio recorder: http://www.c-sharpcorner.com/blogs/audio-recorder-in-c-sharp1

My question is how can I save the recorded file if the application is running in the background and I click the windows shutdown button without closing it first? Is there any way to make an autosave before closing?

Thank you!

Adriannn
  • 21
  • 5
  • 1
    Possible duplicate of [How to detect Windows shutdown or logoff](https://stackoverflow.com/questions/6799955/how-to-detect-windows-shutdown-or-logoff) – Alex K. Dec 13 '17 at 11:18
  • What if user do not want to save changes? Alternative solution is to keep data in files (so you don't need anything extra to do upon shutdown) and provide a mechanism to determine whenever software was exited without saving changes. Upon next start you can show a warning and ask user what to do. – Sinatr Dec 13 '17 at 11:23

1 Answers1

2

It seems to be a Windows Application. So just add a handler for the closing event to your Form and save the file there. That's not foolproof, because if this takes to long, the process will be killed anyway, but there is nothing you can do if that happens anyway.

Another option might be to always stream your audio to file and just close and flush it in the window closing event. Might be the better option.

nvoigt
  • 75,013
  • 26
  • 93
  • 142
  • How can I always stream the audio file and just close and flush it in the window closing event? Thank you! – Adriannn Dec 13 '17 at 11:31
  • I think you should get a better tutorial that actually *explains* what is happening. You can certainly change the application to do that, but it would be a lot better for your understanding, if you had a tutorial that not only instructed you to copy/paste text and compile, but to explain *why*. With such an explanation, you should be able to answer that yourself. So your best bet is to get a *good* book or tutorial. – nvoigt Dec 13 '17 at 11:36