0
GetLastError在ReadFile之後返回1453 ERROR_WORKING_SET_QUOTA。這是否意味着有內存泄漏或什麼?此代碼用於與USB設備進行通信。此過程在10小時內(每40毫秒讀取一次)進行測試,然後出現錯誤。ReadFile已經返回ERROR_WORKING_SET_QUOTA
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);
}
}
}
你爲什麼不使用'File.ReadAllText'方法的任何原因?爲什麼不安全的代碼? –
UnsafeMethods將api包裝到自定義的USB驅動程序FTD2XX.DLL;由於性能要求,我正在使用重疊讀/寫 – baraban
如果更改代碼以僅使用File.ReadAllText進行調試,您會得到什麼錯誤? –