对来自 VB.NET 的非托管 DLL 调用强制使用特定的处理器关联

发布于 2024-12-28 14:03:13 字数 285 浏览 3 评论 0原文

我正在从 VB.NET Web 服务器调用一个函数到自定义编写的非托管 DLL。 如果我们通过多核服务器上的 Web 服务调用这个 DLL,我们就会遇到问题并且它总是会崩溃。

如果我重新启动服务器并使其仅使用单核,它总是运行良好并且永远不会崩溃。

我知道 DLL 调用是导致崩溃的原因,因为我在 DLL 调用之前和之后输出了调试代码。

我可以将 .NET 代码的处理器关联强制为 1 个核心,但这不适用于非托管 DLL。

我如何强制非托管 DLL 仅在单个核心上运行,因为我确信这会解决问题?

I am calling a function from a VB.NET webserver to a custom written unmanaged DLL.
If we call this DLL via a webservice on a multi-core server we run into problems and it always crashes.

If I reboot the server and make it only use a single-core, it always runs fine and never crashes.

I know the DLL call is responsible for the crash as I have outputted debugging code just before and after the DLL call.

I can force the processor affinity of the .NET code to 1 core but this doesn't apply to the unmanaged DLL.

How can I force the unmanaged DLL to only run on a single core as I am sure this will solve the problem?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

沙与沫 2025-01-04 14:03:13

如果您有权访问 DLL 代码,那么您可以在 DllMain 中使用类似以下几行的内容:


DWORD_PTR processAffinityMask = 0x1;

SetProcessAffinityMask( GetCurrentProcess(), processAffinityMask );

这会将 dll 的进程亲和力设置为第一个 CPU。

If you have access to the DLL code then you can use something like the following lines in DllMain:


DWORD_PTR processAffinityMask = 0x1;

SetProcessAffinityMask( GetCurrentProcess(), processAffinityMask );

This will set the process affinity of the dll to the first CPU.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文