public CallbackModelWrapper PopulateImages(CallbackModelWrapper model)
        {
            Init(model);
            var pixels = model.GenerateNewPixelMatrices();
            int amount = 0;

            try
            {
                while (true)
                {
                    for (int i = 0; i < 28; ++i)
                    {

                        for (int j = 0; j < 28; ++j)
                        {
                            byte b = brImages.ReadByte();

                            pixels[i][j] = b;
                        }
                    }

                    byte lbl = brLabels.ReadByte();
                    var image = new DigitImage(pixels, lbl, ++amount);
                    model.Images.Add(image);
                }
            }
            catch (Exception e)
            {
                //will get exception here
                //BinaryReader cannot read past end of file error
                Console.Write(e.ToString());
            }
            brImages.Close();
            brLabels.Close();
            return model;
        }
        private async Task<DigitImage> ReadOneImageAsync(CallbackModelWrapper model, int imageSize, int offset_image, int offset_label, int orderInCollection)
        {
            int bufferSize = imageSize * imageSize;
            byte[] image_bytes = new byte[bufferSize];
            byte[] label_bytes = new byte[1];

            using (FileStream fsi = new FileStream(@"..\..\Files\t10k-images.idx3-ubyte",
        FileMode.Open, FileAccess.Read, FileShare.Read,
        bufferSize: 4096, useAsync: true))
            using (FileStream fsl = new FileStream(@"..\..\Files\t10k-labels.idx1-ubyte",
       FileMode.Open, FileAccess.Read, FileShare.Read,
       bufferSize: 4096, useAsync: true))
            {
                //lock (fsi)
                //{
                //    fsi.copy
                //}
                fsi.Seek(offset_image, SeekOrigin.Begin);
                fsl.Seek(offset_label, SeekOrigin.Begin);

                var tmp_label = fsl.Read(label_bytes, 0, 1);
                var tmp_image = await fsi.ReadAsync(image_bytes, 0, bufferSize);
                //var tmp_image = fsi.Read(image_bytes, 0, bufferSize);
            }

            var pixels = model.GenerateNewPixelMatrices();

            for (int i = 0; i < imageSize; ++i)
            {
                for (int j = 0; j < imageSize; ++j)
                {
                    pixels[i][j] = image_bytes[i * imageSize + j];
                }
            }



            DigitImage image = new DigitImage(pixels, label_bytes[0], orderInCollection);
            return image;
        }
        private async Task Populate_AddImageAsync(CallbackModelWrapper model, CancellationTokenSource cts)
        {
            var index = 0;
            lock (model)
            {
                index = model.index++;
            }
            int bufferSize = model.ImageSize * model.ImageSize;
            var offset_image = model.offset_origin_image + index * bufferSize;
            var offset_label = model.offset_origin_label + index;
            var orderInCollection = index + 1;


            byte[] image_bytes = new byte[bufferSize];
            byte[] label_bytes = new byte[1];
            //
            using (FileStream fsi = new FileStream(model.imagePath,
        FileMode.Open, FileAccess.Read, FileShare.Read,
        bufferSize: 4096, useAsync: true))
            using (FileStream fsl = new FileStream(model.labelPath,
       FileMode.Open, FileAccess.Read, FileShare.Read,
       bufferSize: 4096, useAsync: true))
            {
                var tmp_label = 0;
                var tmp_image = 0;
                try
                {
                    fsi.Seek(offset_image, SeekOrigin.Begin);
                    fsl.Seek(offset_label, SeekOrigin.Begin);

                    tmp_label = fsl.Read(label_bytes, 0, 1);
                    tmp_image = await fsi.ReadAsync(image_bytes, 0, bufferSize, cts.Token);
                    //var tmp_image = fsi.Read(image_bytes, 0, bufferSize);
                }
                catch (TaskCanceledException e)
                {
                    throw e;
                }
                //throw exception here, no byte can be read 
                if (tmp_label == 0 || tmp_image == 0)
                {

                    cts.Cancel();
                    return;
                    //cancellation token only yields exception for later threads
                    //to prevent the current thread continue, either throw an exception or return
                    //the behavior observed is that the taskcancellation exception can't be caught if
                    //I throw an exception here, so just do a return 
                    //throw new Exception("reach the end of stream, use token to cancel all tasks");
                }

            }
            //var t = System.Threading.Thread.CurrentThread.ManagedThreadId;
            var pixels = model.GenerateNewPixelMatrices();

            for (int i = 0; i < model.ImageSize; ++i)
            {
                for (int j = 0; j < model.ImageSize; ++j)
                {
                    pixels[i][j] = image_bytes[i * model.ImageSize + j];
                }
            }



            DigitImage image = new DigitImage(pixels, label_bytes[0], orderInCollection);
            model.Images.Add(image);
        }
        private CallbackModelWrapper PopulateImages(CallbackModelWrapper model, int amount)
        {
            var pixels = model.GenerateNewPixelMatrices();
            for (int di = 0; di < amount; ++di)
            {
                for (int i = 0; i < 28; ++i)
                {
                    for (int j = 0; j < 28; ++j)
                    {
                        byte b = brImages.ReadByte();
                        pixels[i][j] = b;
                    }
                }

                byte lbl = brLabels.ReadByte();

                var image = new DigitImage(pixels, lbl, di + 1);
                model.Images.Add(image);
            }
            brImages.Close();
            brLabels.Close();
            return model;
        }