使用多线程时,C# P/Invoke ODBC32.dll 失败
更新:以下错误实际上是由于我错过的一个简单错误造成的。这里唯一真正的信息是疲倦和愚蠢是一个糟糕的组合。
由于与我们被迫使用的 ODBC 驱动程序的某些特定功能有关的原因,我一直在尝试编写一个直接使用的小型应用程序ODBC 调用。由于 C# 2.0 是我最了解的,因此我一直使用对 ODBC32.dll 的 P/Invoke 调用来完成此操作。
我最初编写的代码是多线程的。但我注意到,一旦我跳转线程,我就会收到 AccessViolationExceptions。例如,当我在一个线程中生成对环境和连接的 IntPtr 引用,然后尝试在另一个线程中使用它们来生成语句 (SQLAllocStmt) 时,一切都会弹出。
我确信我可以解决这个问题,但是这有什么明显的原因吗?调用 ODBC32.dll 分配的非托管内存是否以某种方式绑定到特定线程?
UPDATE: The following error was actually due to a simple bug which I missed. The only real message here that tired and stupid is a bad combination.
For reasons to do with some specific features of an ODBC driver we're forced to use, I've been trying to write a small application which directly uses ODBC calls. Since C# 2.0 is what I know most, I've been doing this using P/Invoke calls into ODBC32.dll.
The code I've written initially has been multithreaded. But I've noticed that as soon as I jump threads I'm getting AccessViolationExceptions. For instance, when I generate IntPtr references to an Environment and Connection in one thread and then try to use these in another thread in the generation of a Statement (SQLAllocStmt), it all goes pop.
I'm sure I can work around this, but is there some obvious reason for this? Is the unmanaged memory allocated by the calls into ODBC32.dll somehow bound to a particular thread?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这取决于:
考虑一下:
This depends on:
Consider: