Ejemplo n.º 1
0
        public async Task <Book> GetBookAsync(Guid id)
        {
            var pageCalculator = new Books.Legacy.ComplicatedPageCalculator();
            var amountOfPages  = pageCalculator.CalculateBookPages();

            return(await _context.Books
                   .Include(b => b.Author)
                   .FirstOrDefaultAsync(b => b.Id == id));
        }
Ejemplo n.º 2
0
 public Task <int> GetBookPages()
 {
     // this long running task will run on a new thread
     return(Task.Run(() =>
     {
         _logger.LogInformation($"ThreadId when entering GetBookPages: {System.Threading.Thread.CurrentThread.ManagedThreadId}");
         var pageCalculator = new Books.Legacy.ComplicatedPageCalculator();
         return pageCalculator.CalculateBookPages();
     }));
 }
Ejemplo n.º 3
0
        // waiting for this result of legacy code
        private Task <int> GetBookPages()
        {
            return(Task.Run(() => // free new thread requested - not optimized for Task.Run()
            {
                var pageCalculator = new Books.Legacy.ComplicatedPageCalculator();
                _logger.LogInformation($"ThreadId when calculating the amount of pages: " +
                                       $"{System.Threading.Thread.CurrentThread.ManagedThreadId}");

                return pageCalculator.CalculateBookPages();
            }));
        }