title: Async loading for winforms
body: <p>In (Android) Apps it is quite common to have ListViews loading and being built while the user is interacting with the interface. In Winforms however the tendency seems to be clicking a button and waiting for the result to be fully loaded before the user can continue navigating through the application.</p>
  
  <p>Since the database access that i am currently using is quite slow, i would like to use the database in async methods to enable the user to keep interacting with the interface, while the data is not fully loaded and displayed. </p>
  
  <p>For example i would like to start an asynchronous method in my Form_Load event to keep gathering data. When this method completes, i want to bind the data to some controls - this will (for now) not change the functionality at all. Thus i want the user not to notice any difference (except for the data being shown or not) when handling the application.</p>
  
  <p>Where am i supposed to place the await keyword to accomplish this? I can't place it in my Load event since this needs to complete for the application to behave "normally". </p>
  
  <p>Is it even possible with async methods to have windows forms being fully reactional while not all methods completed, or am i looking at the 'wrong' functionality for my purposes?</p>
  
  <p>Thank you in advance.</p>
  
  <p>Edit: Following Srirams hint, I made the load-event itself an async sub which worked out well. Here is some simple sample code which shows the desired behaviour:</p>
  
  <pre><code>Public Class DelayedLoadingWindow
  
      Private Async Sub DelayedLoadingWindow_Load(sender As Object, e As EventArgs) Handles MyBase.Load
          Dim awaitedResultOne As Task(Of String) = GetDataOneAsync()
          Label1.Text = Await awaitedResultOne
          Dim awaitedResultTwo As Task(Of String) = GetDataTwoAsync()
          Label2.Text = Await GetDataTwoAsync()
          Dim awaitedResultThree As Task(Of String) = GetDataThreeAsync()
          Label3.Text = Await GetDataThreeAsync()
          Me.Text = "DONE"
      End Sub
  
      Public Async Function GetDataOneAsync() As Task(Of String)
          Await Task.Delay(2000)
          Return "Async Methods"
      End Function
  
      Public Async Function GetDataTwoAsync() As Task(Of String)
          Await Task.Delay(2000)
          Return "are"
      End Function
  
      Public Async Function GetDataThreeAsync() As Task(Of String)
          Await Task.Delay(2000)
          Return "running!"
      End Function
  End Class
  </code></pre>