Reputation: 11
I have a async method in my main form which populates the grid from data retrieve from a website.
I created another class and called that function, when I debug I can see the flow entering the function, reading data from website and populating the grid but in Reality grid remains empty.
Code example is this.. Please help !
Class MainForm
{
public async PopulateGrid()
//goto website
//get data
//updategrid
}
Class newProject
{
MainForm mf = new Mainform;
mf.PopulateGrid();
}
Upvotes: 0
Views: 6117
Reputation: 7122
First, a word of advice: never write async void methods that aren't event handlers. You hide exceptions by using async void
methods. Also, always add the Async
suffix to the asynchronous methods. Here is a proposed new definition:
public async Task PopulateGridAsync() {...}
You should also await all async calls, so ensure that you write:
await mf.PopulateGridAsync();
Most likely you got some exception, but it was hidden due to the void return type.
More info:
Upvotes: 1
Reputation: 131712
We have to guess here. You should provide the full method signature and the code that actually updates the grid. Additionally, when and how do you show the form?
One guess is that your code displays the grid using data from a structure hasn't been filled yet by PopulateGrid. PopulateGrid should force an update of the grid itself after it receives the data, otherwise the grid will never know there are new data.
Upvotes: 0