converting a sync to async in EF RRS feed

  • Question

  • User-2097295820 posted

    Dear Readers,

         I have built a simple demo shopping cart on EF. I read about the async methods. So I have decided to use this in my codes context.SaveAsync();

    Meaning that my app works asynchroniously but I have some questions. In research on building async web apps, I was made to understand that async web apps are very scalable and faster. This is what lead me this path cos I want my app to be very scalable and fast.

    Down to my question. I would paste a code sample and I would ask questions on it. Just want to know if I am on the right track.

    Productcart cart = await obj.createProductcart(.......);
    int result = await obj.storeInvoice(cart.ProductcartID);
    if (result >0){
       return View("...");
        return RedirectToAction("...");

    In my code snippet I after I create a cart for product asynchronizously I am passing cart ID to StoreInvoice()  to create the invoice of the product.

    I read that async method jumps out of it current state to other codes and execute them. Am I right to make the createProductcart() async

    because storeinvoice () need product cartID to be ready before it is executed. Or is StoreInvoice() going to wait for createProductcart() to execute before it is executed.

    Please correct me if my code background on async is faulty. Sorry if my question sound stupid, I have read on asyc but I trying to get my practical background experience right.


    Saturday, September 5, 2015 1:57 PM


  • User-821857111 posted

    StoreInvoice will only execute if the cart id is provided to it. Asynchronous methods allow the thread to be freed up while it is waiting for I/O or database calls to complete, improving efficiency. Any code that relies on the result of an asynchronous method call still has to wait for the result of that method before it can be executed.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, September 6, 2015 4:22 PM