Skip to main content
August 25, 2011
Question

Application not closing when requested by uninstaller

  • August 25, 2011
  • 1 reply
  • 440 views

Hello.

My application needs to perform some lengthy actions when it's closing (upload user's documents to a server). I've added something like this and it worked fine:

...
     NativeApplication.nativeApplication.addEventListener(Event.EXITING, onApplicationExiting);
...
var isNotGarbage: TTimer=null;
protected function onApplicationExiting(event: Event): void
{
   if (event.type==Event.EXITING)
    {
     event.preventDefault();
     callLater(function (): void { applicationTryExit(); } );
     isNotGarbage=new Timer(100, 0); //store the timer globally to avoid it being garbage-collected
     isNotGarbage.addEventListener(TimerEvent.TIMER,
       function (event: Event): void { applicationTryExit(); } );
     isNotGarbage.start();
    };
}

protected function applicationTryExit(): void
{
   //the app never gets here when uninstalling
   if (everythingUploaded)
    {
     isNotGarbage.stop();
     isNotGarbage=null;
     NativeApplication.nativeApplication.exit(0);
    };
}

Sadly, I've realized that there's a problem: when uninstalling the application while it is running, the Windows Vista or Windows 7 send the "EXITING" event to the application (after asking the user), but from that point on, the "callLater" does not do anything, and no timers work any more. But I do need to delay the exit, because uploading the files to server cannot be performed synchronously (before returning from onApplicationExiting()).

Windows XP do not try to "force close" the application, instead they simply ask the user to close the app before continuing, and that works fine.

The problem is, that the application hangs in the TaskManager, and it also holds a reference to the installation folder. That means the application cannot be run again, and it also will not reinstall, because there's the empty folder. Telling users to kill it and delete the folder manually is just not good.

So, my questions are:
  1. Is there something wrong with that code?
  2. How do I distinguish between normal application EXITING (clicking the red X) and the uninstaller's EXITING? The event's properties and NativeApplication's state seem to be exactly the same.
  3. Is there some trick to upload files through HTTPService synchronously?
  4. Can anyone reproduce this?

Obviously, I cannot stop users from doing this.

I'm still using SDK 3.6, because the 4.0's AdvancedDataGrid is just unusable.

  Milan Vandrovec

This topic has been closed for replies.

1 reply

August 25, 2011

I have "solved" it by implementing a /CLOSE command line parameter, and calling that from a custom uninstaller.

So the problem is not urgent any more, although it is still there.

  Milan

chris.campbell
Legend
August 25, 2011

Hi Milan,

Thanks for posting your workaround.  It's a great idea.

Chris