GetLastError在ReadFile之后返回1453 ERROR_WORKING_SET_QUOTA。是不是意味着有内存泄漏什么的?此代码用于与usb设备通信。这个过程工作了10个小时(每40毫秒读一次),然后出现错误。
uint ReadBytesCount = 0;
byte[] bytes = new byte[0x8000];
fixed (byte* p = bytes)
{
if (UnsafeMethods.ReadFile(handle, p, 0x8000, out ReadBytesCount, intOverlapped) == 0)
{
int hr = UnsafeMethods.GetLastError(handle);
if (hr == UnsafeMethods.ERROR_ACCESS_DENIED)
{
doCleanup = true;
break;
}
if (hr == NativeMethods.ERROR_IO_PENDING)
{
int error = 0;
// if we get IO pending, MSDN says we should wait
// on the WaitHandle, then call GetOverlappedResult
// use timeout to ensure that first time read
bool success = waitReadEventWaitHandle.WaitOne(1000);
if (success)
{
uint ReadInProgressCount = 0;
success = UnsafeMethods.GetOverlappedResult(
handle,
intOverlapped,
ref ReadInProgressCount,
false);
if (!success)
error = UnsafeMethods.GetLastError(handle);
ReadBytesCount += ReadInProgressCount;
if (!success && error != 0)
{
// Ignore ERROR_IO_INCOMPLETE, because there's a chance
// one of those while shutting down
if (!(
(error == UnsafeMethods.ERROR_IO_INCOMPLETE)
&& ShutdownLoop)
)
Debug.Assert(false,
"GetOverlappedResult,might leak intOverlapped memory"
+ error.ToString());
}
}
}
else if (hr != UnsafeMethods.ERROR_INVALID_PARAMETER)
{
// ignore ERROR_INVALID_PARAMETER errors.
Debug.Assert(false, "ReadUsbLoop returned error " + hr);
}
}
}发布于 2011-07-28 13:32:24
我发现的唯一有意义的信息是mysql列表中的配额1453 (0x5AD)用于InnoDB后端。
发生错误时,Server工作人员将生成100 and,并再次尝试读取操作。此循环将继续进行,直到成功发出I/O。一个简化的示例演示了此行为。
WHILE( FALSE == ReadFile()
&& (1450 == GetLastError() || 1453 == GetLastError())
)
{
Yield(100);
}这使我得出结论,我应该尝试100 ms的睡眠线程,然后重试read。
uint ReadBytesCount = 0;
byte[] bytes = new byte[0x8000];
fixed (byte* p = bytes)
{
if (UnsafeMethods.ReadFile(handle, p, 0x8000, out ReadBytesCount, intOverlapped) == 0)
{
int hr = UnsafeMethods.GetLastError(handle);
if (hr == UnsafeMethods.ERROR_ACCESS_DENIED)
{
doCleanup = true;
break;
}
if (hr == NativeMethods.ERROR_IO_PENDING)
{
// do something
}
else if (hr == UnsafeMethods.ERROR_WORKING_SET_QUOTA ||
hr == UnsafeMethods.ERROR_NO_SYSTEM_RESOURCES)
{
Thread.Sleep(100);
}
else if (hr != UnsafeMethods.ERROR_INVALID_PARAMETER)
{
// ignore ERROR_INVALID_PARAMETER errors.
Debug.Assert(false, "ReadUsbLoop returned error " + hr);
}
}
}更新:不,它没有帮助。现在我正在考虑抛出超时错误并重新打开一个设备。
https://stackoverflow.com/questions/6845743
复制相似问题