Question

I've designed a program to run off flash drives. My idea was to put an Eject button on the program so you can easily 'safely remove' the drive. However on Mac, you can't unmount the drive whilst the application is still running unless you do a force unmount. My question is, should I be doing this?

Isn't a force unmount similar to just pulling the drive out? Is it safe to make this option easily available?

Also is there any alternative?

Était-ce utile?

La solution

I take it your application is running from the disk itself, yes?

Rather than force-eject the drive, you should spawn a separate process. Basically you write a little helper program that waits for your main program to quit, then ejects the disk, and finally quits itself. When you spawn the helper process, you will have to do so "without waiting." The terminology may be different depending on the language you're using ("in a new thread" or "detaching a process") but the basic idea is that you must launch a helper program to take over from your main program in such a way that your main program can quit.

It's bad form to force eject - you can't be sure the drive is not in use. On a Mac, for example, you have Spotlight reading/writing to external disks at all sorts of times.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top