そこで、ファイルを開いて変更を監視し、Windows フォームに表示する小さなアプリを作成しました。
私は問題を抱えていますが、ファイルが更新されるたびに、最初にファイルをロードすると正常に動作します。
これは私が使用しているコードの一部です。次のことがわかります。
Offset and length were out of bounds for the array or count is greater than the number of elements from index to
the end of the source collection.
このロジックは正常に機能するはずなので、正確に何が問題なのかわかりません。最初のロードで m_lastFilePosition が 0 に設定され、予想されるサイズのバイト配列が作成されます。
m_readingFile = true;
FileStream l_stream = new FileStream(m_fileToWatch, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
FileInfo l_info = new FileInfo(m_fileToWatch);
buffer = new byte[l_info.Length-m_lastFilePosition];
l_stream.BeginRead(buffer,
(int)m_lastFilePosition,
(int)(l_info.Length - m_lastFilePosition),
new AsyncCallback(FileReadCallback),
l_stream);
誰もこれに遭遇したことがありますか?