I managed to do it by calling the TerminateProcess
Windows API call: (don't do this!)
[DllImport("kernel32.dll")]
static extern int TerminateProcess(IntPtr processIdOrHandle, uint exitCode);
[DllImport("kernel32.dll")]
static extern IntPtr GetCurrentProcess();
public static void Exit(uint code) {
TerminateProcess(GetCurrentProcess(), code);
}
The code makes me very nervous, however: TerminateProcess
is a rather nasty "immediate kill switch"-kind of call that will immediately kill sllauncher.exe
. If sllauncher.exe
usually does any kind of cleanup after a Silverlight application is closed, which I assume it might, that cleanup is now omitted. I'm very wary of taking this approach.
I figured that another way to "communicate" with the parent process is by writing something of an exit code to a temporary file, however Silverlight's Environment.GetSpecialFolder
call does not give me access to anything like a temp directory.
I'm probably going to have to P/Invoke to the Windows API to find the temporary directory, and then write a file to it, and read that out from the parent process.
(note: this was Silverlight 5. I'm not sure to what extent you can P/Invoke at all on SL4)