Question

How can I notify another application which is in different domain that current running application has crashed? in the other words, Is it possible to negotiate two different applications in separate domain?

Thanks in advance.

Was it helpful?

Solution

You can use named pipes for this sort of IPC. For this, look into System.IO.Pipes namespace and excellent NamedsPipeServerStream & NamedPipeClientStream classes.

Note that you can use anonymous pipes only for inter process communications within the same domain, while you can use named pipes for IPC in separate domains (i.e. across PCs on the same intranet).

OTHER TIPS

Yes it is possible. How well this is supported in .NET types will vary depending on how you are going to make the determination of "has crashed".

Basically the monitoring application needs to supply credentials suitable to access the system that should be running the monitored application. This is exactly what one would do to copy a file to/from another domain by starting with something like:

net use \\Fileserver1.domain2.com\IPC$ /user:DOMAIN\USER PASSWORD

or its API equaivalent.

If you use WMI (this is the obvious approach, it is easy to list the processes on a remote system with a query for Win32_Process) you can supply credentials (eg. with the scripting interface or in .NET).

You can use the AppDomain.UnhandledException event to signal the other AppDomain, possibly through a named Mutex. Since they're system-wide, you could create one called "MyAppHasCrashed" and lock it immediately. When you hit an unhandled exception, you release the mutex. On the other side, have a thread that waits on the mutex. Since it's initially blocked, the thread will sit waiting. When an exception occurs, the thread resumes and you can handle the crash.

Mutex crashed = new Mutex(true, "AppDomain1_Crashed");
...
private void AppDomain_UnhandledException(...)
{
    // do whatever you want to log / alert the user
    // then unlock the mutex
    crashed.ReleaseMutex();
}

Then, on the other side:

void CrashWaitThread()
{
    try {
        crashed = Mutex.OpenExisting("AppDomain1_Crashed");
    }
    catch (WaitHandleCannotBeOpenedException)
    {
        // couldn't open the mutex
    }
    crashed.WaitOne();
    // code to handle the crash here.
}

It's a bit of a hack, but it works nicely for both inter-domain and inter-process cases.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top