Repost: Isolation In AppDomain - How to prevent the main AppDomain to crash when another AppDomain C

  • Thread starter Thread starter José Joye
  • Start date Start date
J

José Joye

I have a windows service where I create another appdomains. In the newly
created AppDomain, I make use of a C library. If I issue an Abort(1) within
this library, it simply hard stop my main AppDomain!!!!!!!!!!!!How could I
prevent my main AppDomain to stop when the other stopped?Thanks a lot,José
 
Jose,

Unfortunately, in C, the abort function will terminate the process that
it is running in. If it does this, then I don't think that there is a
workaround for it. You will have to run this separately in another process
and marshal any calls/values back to you.

Hope this helps.
 
Harrrrg,

Let's say I make a modification to this legacy library and install a "signal
handler" that will send, through a delegate, information that an exception
occured.
Is there a way to unload the AppDomain where the C code is loaded without
having my main domain to miserably terminate?

José

Nicholas Paldino said:
Jose,

Unfortunately, in C, the abort function will terminate the process that
it is running in. If it does this, then I don't think that there is a
workaround for it. You will have to run this separately in another process
and marshal any calls/values back to you.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

José Joye said:
I have a windows service where I create another appdomains. In the newly
created AppDomain, I make use of a C library. If I issue an Abort(1) within
this library, it simply hard stop my main AppDomain!!!!!!!!!!!!How could I
prevent my main AppDomain to stop when the other stopped?Thanks a lot,José
 
Hi Jose,
*abort* terminates the whole process. So all application domains on it will
be terminated. What you can do is to install signal handler for SIGABRT
signal. Hopefully you can do it form managed code with P/Invloke.

So maybe you will install that handler form the same application domain that
you want to terminate.
If it is a GUI you can call Application.Exit. If it is not.... I don't
know... you have choices...
Ultimately you can call AppDomain.CurrentDomain.Unload.

HTH
B\rgds
100
 
Jose,

This would work much better. If you have your C code changed so that it
issues an error code of some sort, instead of calling abort, that would be
optimal. Then, from the managed side, you can decide what to do when it
fails.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

José Joye said:
Harrrrg,

Let's say I make a modification to this legacy library and install a "signal
handler" that will send, through a delegate, information that an exception
occured.
Is there a way to unload the AppDomain where the C code is loaded without
having my main domain to miserably terminate?

José

message news:%[email protected]...
Jose,

Unfortunately, in C, the abort function will terminate the process that
it is running in. If it does this, then I don't think that there is a
workaround for it. You will have to run this separately in another process
and marshal any calls/values back to you.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

José Joye said:
I have a windows service where I create another appdomains. In the newly
created AppDomain, I make use of a C library. If I issue an Abort(1) within
this library, it simply hard stop my main AppDomain!!!!!!!!!!!!How
could
 
I did this directly in the C Library (just as a quick test).

This sounds now much better. I'm able to unload the appDomain directly
within the faulty AppDomain.
I'm also able to reload it again from the main AppDomain.

HOWEVER!!!!
I always get a popup message when the dll containing the C code terminates:Visual C++ Runtime Library
Runtime Error!
This application has requested the Runtime to terminate it in an unusual
way.
And the Service locks until I press OK...

Is there a way to prevent such a message to be thrown?




======= C code snippet =========
// JOJ
signal(SIGABRT, inthandler);
signal(SIGFPE, inthandler);
signal(SIGILL, inthandler);
signal(SIGSEGV, inthandler);
// JOJ

....
....
void
inthandler (int arg)
{
// JOJ: Write info to local memory log and call our delegate to inform
about the problem
......
(*ExitRamitPtr)(9999);
return;
}
 
Got it. Need to call
_set_error_mode(_OUT_TO_STDERR);

Thanks for your great help!

José
 
Back
Top