Returning Values from Other Threads

In the previous example, you most likely thought it odd, or at least inefficient, to have to notify the user when the thread is done, and then to have the user click a button that loads the data into the grid. A seemingly obvious answer would be to have the GetData sub return an ADO.NET dataset when it is done, and then have the calling procedure fill the grid.

There are two problems with this approach, however. First, because you are running the GetData sub on a separate thread, the calling routine continues executing immediately after starting the new thread. That means any code you had to fill the grid after calling GetData would execute immediately, even though GetData would most likely not be finished. ...

Get A Programmer's Introduction to Visual Basic® .NET now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.