在多线程里面,为变量赋值时, 最好采用这种形式,锁:
InterlockedExchange(a,0);The functions InterlockedExchange, InterlockedCompareExchange, InterlockedDecrement, InterlockedExchangeAdd, and InterlockedIncrement provide a simple mechanism for synchronizing access to a variable that is shared by multiple threads. The threads of different processes can use this mechanism, if the variable is in shared memory.The variable pointed to by the Target parameter must be aligned on a 32-bit boundary; otherwise, this function will fail.

解决方案 »

  1.   

    内存泄露了...装个Eurekalog检查一下哪行出错了.哪个地方内存出错了。
      

  2.   

    你的代码真的错综复杂。。上全代码吧。帮你看看是代码还是ID控件问题。。
    邮箱[email protected]
      

  3.   

    程序在调试阶段出现错误截图如下:
    我发现每次出现非法操作都是在IDHTTP出现TIMEOUT的时候,有时候能继续执行下去,有时候就一直出现上图那个非法操作,看这个错误应该是IDHTTP已经释放了还在使用,可事实上我的IDHTTP根本就没有释放的代码,请问这个到底是个什么问题啊?
      

  4.   

    补充下,我为啥确定是IDHTTP的出错:
    因为出错每次都是在IDHTTP的超时之后,且程序停留在IDHTTP单元的FHTTPProto.BuildAndSendRequest(URL)的下一行,应该确定是FHTTPProto.BuildAndSendRequest(URL);这一行出错了。
      

  5.   

    现在发现是运行到:
    resp.Free;出错
    可是resp已创建啊,释放怎么可能出错?