Sure. It really depends on what I am trying to accomplish. But let's take the scenario that you have a lot of BOs that must be loaded and there may be a number of child BOs that need to be loaded as well. In this case, the easiest solution is to use the ThreadManager class and load each of the child BOs (and potentially the parents as well) on a thread. For example, let's take the scenario below:Tables with Respective BOs
Customers (Parent BO)
CustomerNotes (Child)
CustomerProducts (Child)
CustomerOrders (Child)
Now let's assume that I have the primary key of the parent (there are a lot of different scenarios that you can work this format into). I am going to load the parent first, then load all of the children at the same time.
'-- Load the parent record
Customers.FillByPrimaryKey(customerPK)
OK, once the parent is loaded (and if you have the PK you may not really need to wait for the parent to load...but you get the idea) I want to spawn 3 threads to load all of the children at the same time. The best way to do this is to create a method for each child BO to load:
Private Sub Fill_CustomerNotes()
CustomerNotes.FillByParentPrimaryKey(Customers.cust_Pk)
End Sub
Private Sub Fill_CustomerProducts()
CustomerProducts.FillByParentPrimaryKey(Customers.cust_Pk)
End Sub
Private Sub Fill_CustomerOrders()
CustomerOrders.FillByParentPrimaryKey(Customers.cust_Pk)
End Sub
But I still need to call these on a thread. Drop a ThreadManager on the form and name it something like, threadManagerChildrenRecords. Once the parent BO has been loaded (or you are ready to load the children) start a process for each fill method:
threadManagerChildRecords.AddProcess(Addressof Fill_CustomerNotes, "Notes")
threadManagerChildRecords.AddProcess(Addressof Fill_CustomerProducts, "Products")
threadManagerChildRecords.AddProcess(Addressof Fill_CustomerOrders, "Orders")
Once each thread completes, the ThreadCompleted event will fire and you can test on the name of the thread specified in the AddProcess call. In most cases, though, you can just handle the AllThreadsCompleted event of the thread manager to launch your post query logic (i.e. populate a list, grid, etc.).
This is a pretty basic overview, but it should at least give you some ideas. We have taken this to another level in our medical software to even load the form (folders in our medical software) on a background thread and the once completed bring it to the main thread...this would require a much longer explanation. But we use the logic explained above for the loading of child records in a number of occasions once the form has been loaded. Hope that makes sense