Ejemplo n.º 1
0
        static void TaskEndReadCallback(IAsyncResult asyncResult)
        {
            FileCheckerState tempState = (FileCheckerState)asyncResult.AsyncState;
            int readCount = tempState.FStream.EndRead(asyncResult);

            if (readCount < tempState.State.Buffer.Length - tempState.State.Overlap)
            {
                Array.Clear(tempState.State.Buffer, (readCount + tempState.State.Overlap), tempState.State.Buffer.Length - (readCount + tempState.State.Overlap));
            }

            CheckBufferState state = tempState.State;

            Task.Factory.StartNew((arg)
                                  =>
            {
                try
                {
                    CheckBufferState innerState = (CheckBufferState)arg;

                    MatchType matchType = MatchType.FullMatch;
                    CheckBuffer(state.Buffer, state.DiskFile, state.FileName, state.BlockSize, state.HashFull, ref matchType, state.Offset);
                    state.MatchType = matchType;

                    // Signal the main thread that the verification is finished.
                    tempState.ManualEvent.Set();
                }
                finally
                {
                    //concurrencySemaphore.Release();
                }
            }, state);

            //tempState.FStream.Close();
        }
Ejemplo n.º 2
0
        // When BeginRead is finished reading data from the file, the
        // EndReadCallback method is called to end the asynchronous
        // read operation and then verify the data.
        static void EndReadCallback(IAsyncResult asyncResult)
        {
            FileCheckerState tempState = (FileCheckerState)asyncResult.AsyncState;
            int readCount = tempState.FStream.EndRead(asyncResult);

            if (readCount < tempState.State.Buffer.Length - tempState.State.Overlap)
            {
                Array.Clear(tempState.State.Buffer, (readCount + tempState.State.Overlap), tempState.State.Buffer.Length - (readCount + tempState.State.Overlap));
            }

            CheckBufferState state = tempState.State;

            MatchType matchType = MatchType.FullMatch;

            CheckBuffer(state.Buffer, state.DiskFile, state.FileName, state.BlockSize, state.HashFull, ref matchType, state.Offset);

            state.MatchType = matchType;

            //tempState.FStream.Close();

            // Signal the main thread that the verification is finished.
            tempState.ManualEvent.Set();
        }