2011-07-27 106 views
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); 
     } 
    } 
} 
+0

你爲什麼不使用'File.ReadAllText'方法的任何原因?爲什麼不安全的代碼? –

+0

UnsafeMethods將api包裝到自定義的USB驅動程序FTD2XX.DLL;由於性能要求,我正在使用重疊讀/寫 – baraban

+0

如果更改代碼以僅使用File.ReadAllText進行調試,您會得到什麼錯誤? –

回答

0

我發現的唯一有意義的信息是在mysql bugs list unconditional exit(1) on ERROR_WORKING_SET_QUOTA 1453 (0x5AD) for InnoDB backend

當發生錯誤時,SQL Server工作負載產生100ms並嘗試再次讀取 操作。該循環繼續,直到I/O成功發出。 一個簡化的例子演示了這種行爲。

WHILE(  FALSE == ReadFile() 
    && (1450 == GetLastError() || 1453 == GetLastError()) 
) 
{ 
    Yield(100); 
} 

這使我得出結論,我應該嘗試睡眠線程100毫秒,然後重試讀取。

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); 
     } 
    } 
} 

更新:不,這並沒有幫助。現在我正在考慮拋出超時錯誤並重新打開設備

相關問題