Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running function from an unmanaged dll inside a C# thread

Here's my problem: I have an unmanaged dll that I made.I'm calling one of this dll's functions in my C# code, using PInvoke. Under certain conditions, in the dll function, I want to be able to terminate the thread that is running the function.How would I achieve that?

Sorry if it is a stupid question, but I'm a total noob when it comes to threading:)

like image 486
Emil D Avatar asked Jun 07 '26 18:06

Emil D


1 Answers

Man, that sounds dangerous. Why terminate the thread? You might be in a thread you don't own depending on how you're marshalling the call. Either ways, it seems like your best option is to return something to indicate you want to terminate the thread and have the managed code handle it gracefully. Don't try to kill the thread in native code.

like image 145
psychotik Avatar answered Jun 09 '26 07:06

psychotik



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!