我正在用c#编写一个软件,它需要多次调用,并且需要多个线程调用c ++非托管dll中的函数.
我有一个这样的C++文件:
// "variables" which consist in some simple variables (int, double)
// and in some complex variables (structs containing arrays of structs)
extern "C"
{
__declspec(dllexport) int function1()
{
// some work depending on random and on the "variables"
}
}
Run Code Online (Sandbox Code Playgroud)
和那样的C#类
public class class1
{
// "variables" <--- the "same" as the C++ file's ones
// Dll import <--- ok
public void method1()
{
int [] result;
for(int i=0; i<many_times; i++)
{
result = new int[number_of_parallel_tasks];
Parallel.For(0, …Run Code Online (Sandbox Code Playgroud)