private void Write()
        {
            var mongoClient = new MongoClient();
            var bookCtxNew = new BookContextNew(mongoClient);
            
            int newBooksCount = 0;

            Book book;
            var booksToSave = new List<Book>();
            var taskList = new List<Task>();


            while (!readFinished)
            {
                Thread.Sleep(10000);

                while (NewBooks.TryDequeue(out book))
                {
                    booksToSave.Add(book);
                    newBooksCount++;

                    if ((newBooksCount % 10000) == 0)
                    {
                        taskList.Add(bookCtxNew.Books.InsertManyAsync(booksToSave));
                        Console.WriteLine("Inserting {0} new books.", newBooksCount);
                        booksToSave = new List<Book>();
                    }
                }

                if (booksToSave.Count > 0)
                {
                    Console.WriteLine("Inserting {0} new books.", newBooksCount);
                    taskList.Add(bookCtxNew.Books.InsertManyAsync(booksToSave));
                    booksToSave = new List<Book>();
                }
                
            }


            

            //Wait for all tasks to finish
            Console.WriteLine("Waiting for tasks to complete ...");
            Task.WaitAll(taskList.ToArray());

        }
 public GenerateNewBooks(BookContextNew newBookCtx, AuthorContext autCtx, BookContext bookCtx)
 {
     this.newBookCtx = newBookCtx;
     this.autCtx = autCtx;
     this.bookCtx = bookCtx;
 }