Пример #1
0
        private void ReaderWorkerStart()
        {
            try
            {
                while (true)
                {
                    if (service.Token.IsCancellationRequested)
                    {
                        return;
                    }

                    int    localPartIndex;
                    int    readByteCount;
                    Stream partOfInputStream;
                    lock (mutex)
                    {
                        if (service.InputStreamIsSliced)
                        {
                            return;
                        }

                        var countToRead = GetCountToRead(inputStream);

                        partOfInputStream = service.GetNewStream(countToRead);

                        readByteCount = inputStream
                                        .CopyTo(partOfInputStream, new byte[countToRead], 0, countToRead);

                        if (readByteCount == 0)
                        {
                            service.InputStreamIsSliced = true;

                            inputStream.Close();

                            return;
                        }

                        service.IncrementReadPartCount();

                        localPartIndex = globalPartIndex;

                        globalPartIndex++;
                    }

                    partOfInputStream.Seek(0, SeekOrigin.Begin);

                    GetParameters(partOfInputStream, readByteCount, localPartIndex)
                    .StartWorker();
                }
            }
            catch (Exception e)
            {
                var errorMessage = "Exception in writer worker: " + e.Message;

                service.HandleException(e, errorMessage);
            }
        }