We continue to work out a corporate plan to form the right public opinion about Microsoft and its technologies :) Time is.
So, here's a technical problem. As far as I could find, her explanations are not even found in Richter. By the decision itself, I hope to come later, when there will be an opportunity to “sit up behind the computer” at the computer, but for now the condition.
As you
know , .Net was designed with an eye to the possibility of deep interaction with native code and COM. We will not understand now whether it was a technical or political decision, the important thing is that interaction with unmanaged code is a complex problem, and a lot of developer’s blood can drink where he didn’t expect. The proposed task is one of these.
')
UPD: The solution is here:
habrahabr.ru/blogs/net/69650Imagine the following code:
IntPtr ptr = Marshal.AllocHGlobal(500); // exception
try
{
// -
}
finally
{
Marshall.FreeHGlobal(ptr);
}
The code allocates some (500 bytes) amount of unmanaged memory. Well, it highlights and let it stand out, so what?
And that's what
Imagine that this code is executed in a separate thread; and at that moment, when memory allocation
already happened, but
before the pointer to the selected unmanaged memory area was copied to the IntPtr variable, the thread was interrupted with a ThreadAbortException. The allocated unmanaged memory will hang in the process and will be freed only upon completion of the process. This is not a problem for short-lived scripts, but it seriously spoils the life of the developer of long-lived applications — application servers, services, and other mission-critical software.
How would you solve this problem? And is there a solution? Skeptics with the argument “this is so unlikely, therefore, you are not sure to think about it” grieving - if the opportunity is there, it will certainly come true; and it will be very sad if this happens only on production. Write, I will try to respond to comments promptly :)