简体   繁体   中英

What is the best threading approach to this issue in C#?

I have about 30 calculations that need to be done on a few thousand data points. The calculations are done in a 3rd party library. Each call can be done in parallel so I was thinking of putting the call into several threads.

The issue that I get is how to properly terminate the calls if need be. Since I don't have access to the lib which is where most of the time is, I can't exit the thread in a nice manner.

Any suggestions?

Thanks.

If the 3rd party library is a managed library, or spends most CPU time in managed code, you can call it from a separate appdomain and nuke the whole appdomain when you need to terminate calculations. If the calculations are mainly in unmanaged code, run the calculations as a separate process and nuke the whole process. Any other approaches are subtly dangerous and therefore unadvisable.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM