public long Find(byte[] bytes, long startIndex)
{
int match = 0;
int bytesLength = bytes.Length;
_abortFind = false;
for (long pos = startIndex; pos < _byteProvider.Length; pos++)
{
if (_abortFind)
return -2;
if (pos % 1000 == 0) // for performance reasons: DoEvents only 1 times per 1000 loops
Application.DoEvents();
if (_byteProvider.ReadByte(pos) != bytes[match])
{
pos -= match;
match = 0;
_findingPos = pos;
continue;
}
match++;
if (match == bytesLength)
{
long bytePos = pos - bytesLength + 1;
Select(bytePos, bytesLength);
ScrollByteIntoView(_bytePos + _selectionLength);
ScrollByteIntoView(_bytePos);
return bytePos;
}
}
return -1;
}