Exemple #1
0
        private void StartWrite()
        {
            // var threadName = Thread.CurrentThread.Name ?? "Main";
            //Console.WriteLine($"{threadName} start");
            using (var destinationStream = new FileStream(DestinationFileName, FileMode.Create, FileAccess.Write))
            {
                try
                {
                    while (true)
                    {
                        var task = QueueToWrite.Dequeue();
                        if (task == null)
                        {
                            break;
                        }
                        if (task.RethrowException != null)
                        {
                            throw new Exception(task.RethrowException);
                        }
                        //Console.WriteLine($"{threadName} writing {task.UncompressedOffset}");

                        destinationStream.Seek(task.UncompressedOffset, SeekOrigin.Begin);
                        destinationStream.Write(task.Buffer, 0, task.Buffer.Length);
                        ExecutionStatus.IncrementStatus();
                    }
                }
                catch (Exception ex)
                {
                    destinationStream.Flush(false);
                    throw new Exception(ex.Message);
                }
            }
            //Console.WriteLine($"{threadName} end");
        }