Catching unmanaged crashes in MC++

T

TheLetti

Hello out there,

is there any possibility for me to catch or avoid crashes caused within
unmanaged code?

The situation:
I'm writing a managed wrapper in MC++, and in there I use some
unmanaged COM methods for creating thumbnails.

The problem: One special line may cause a crash, and subsequently
blocks my whole application.

The line looks like this:

// unmanaged:
IExtractImage * peiURL = NULL; // use shell interface
HR_TRY(hr = peiURL->Extract(pThumbnail)); // application hangs in
this line sometimes

So is there any way for me to avoid blocking the whole app?
Normal exception-handling won't do since this com-method doesn't throw
any exceptions.
Maybe I could call this function in a separate thread, and if it
doesn't respond within a certain time I should kill the thread
programatically?
Are there other ways out there?

Thanks in advance,

TheLetti
 
A

Atul

Extracting thumbnails from a background thread is a good solution from the
performance point of view as well. Thumbnail extraction can be quite slow
for some items.

- Atul
Sky Software http://www.ssware.com/
Drop-In Windows Explorer-Like Shell Browsing UI for your apps.
 
T

TheLetti

Hi Atul,

thank you for your suggestions. Indeed, I have already tried executing
this thumbnail code within a separate thread, and this works now for
me!


greez,

TheLetti
 
T

TheLetti

Hi again,

while implementing thumbnail extraction within a seperate thread, I
encountered another problem:

I'm using the System::Threading::Thread class to put my code into a
thread.
After starting the thread, which extracts the thumbnail actually, I
call myThread->Join(timeout)

This method returns either if the thread has terminated successfully,
or after a specified timeout.

In case of the timeout the thread hangs in my unmanaged code, and so
the thread stays alive.
All I want to do now is to terminate this stubborn thread.
Unfortunately, calling myThread->Abort() doesn't do the trick, because
it hangs in unmanaged code.

The documentation says this:

"If a thread makes an unmanaged call into the operating system that has
blocked the thread in unmanaged code, the runtime will not take control
of it for System.Threading.Thread.Interrupt or
System.Threading.Thread.Abort. In the case of
System.Threading.Thread.Abort, the runtime marks the thread for Abort
and takes control of it when it re-enters managed code."

So the thread couldn't be aborted, because it never returns to managed
code again.

My question now is, if there is ANY possibility to terminate the thread
anyways?


thx in advance,

TheLetti
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top