简体   繁体   English

用C#解决此问题的最佳线程方法是什么?

[英]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. 我需要在几千个数据点上进行大约30个计算。 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. 如果第三方库是托管库,或在托管代码中花费了最多的CPU时间,则可以从单独的appdomain调用它,并在需要终止计算时对整个appdomain进行核对。 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. 任何其他方法都具有潜在的危险,因此不建议使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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