none
Async and Await When Loading Data RRS feed

  • Question

  • button1.KeyDown+=async(o,n)=> {

    //This is a search function, the user will type something on

    // a textbox then in every keypress, the application will connect

    //to the database and search if the typed data has been found

    //then bind it to a gridcontrol

    var getData=Task.Run(()=> Call_To_Database_NotAsync); var result=await getData; gridcontrol.Datasource=result; }

    Is there a possibility that the grid control will contain no data at all when the user types fast and the connection to the database is slow?

    Regards

     
    • Edited by Dikong42 Friday, July 6, 2018 8:40 PM
    Friday, July 6, 2018 8:38 PM

All replies

  • I think that if Call_To_Database_NotAsync or server-side functions are not designed to support multiple parallel executions, then it is possible to observe undesirable effects. Find a way to cancel the requests that are obsolete.

    • Edited by Viorel_MVP Sunday, July 8, 2018 7:15 PM
    Sunday, July 8, 2018 6:23 PM
  • Hi Dikong42,

    Why not the load the data to memory and research the data in memory.

    Best regards,

    Zhanglong


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, July 9, 2018 3:10 AM
    Moderator