SomeFunc()
{
 int returnCode = 0;
 int[] data = new int[5];
 returnCode = Test.Read(5,out data[0]);
}直接运行没有问题,returnCode和data都有正确返回值,但是在线程中执行SomeFunc就只能得到returnCode,而data都是0?
Test.Read是别人的,不知道里面是什么。

解决方案 »

  1.   

    SomeFunc函数里没有涉及全局变量,应该不会有问题的啊
      

  2.   

    是啊,实在搞不懂了,我用的是VS2005
    unsafe有没有关系,Read是C++写的
      

  3.   

     这样试试
          
    private object objLock = new object();
            SomeFunc()
            {
                int returnCode = 0;
                int[] data = new int[5];
                lock (objLock)
                {
                    returnCode = Test.Read(5, out data[0]);
                }
            }
      

  4.   

    黑匣子不好下结论,最好看下test中的函数干了些什么。
      

  5.   

    Details of Read Functions (Custom Interface)
    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
      

  6.   


    //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
      

  7.   

    SomeFunc()
    {
     int returnCode = 0;
     int[] data = new int[5];
     returnCode = Test.Read(5,out data);
    }这样试试