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.