SomeFunc()
{
int returnCode = 0;
int[] data = new int[5];
returnCode = Test.Read(5,out data[0]);
}直接运行没有问题,returnCode和data都有正确返回值,但是在线程中执行SomeFunc就只能得到returnCode,而data都是0?
Test.Read是别人的,不知道里面是什么。
{
int returnCode = 0;
int[] data = new int[5];
returnCode = Test.Read(5,out data[0]);
}直接运行没有问题,returnCode和data都有正确返回值,但是在线程中执行SomeFunc就只能得到returnCode,而data都是0?
Test.Read是别人的,不知道里面是什么。
unsafe有没有关系,Read是C++写的
private object objLock = new object();
SomeFunc()
{
int returnCode = 0;
int[] data = new int[5];
lock (objLock)
{
returnCode = Test.Read(5, out data[0]);
}
}
hResult = object.Read(lSize, *lplData, *lplRetCode)
HRESULT hResult Returned value of COM Output
LONG lSize Number of read points Input
LONG *lplData Read device values Output
LONG *lplRetCode Returned value of communication function Output
//Visual C++R .NET :
iRet = object.ReadDeviceBlock( iSize, *iplData)
int iRet; //Returned value Output
int iSize; //Number of read points Input
int *iplData; //Read device values Output
{
int returnCode = 0;
int[] data = new int[5];
returnCode = Test.Read(5,out data);
}这样试试