0

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(); } 
2
  • Where is the code that updates the grid? There is absolutely no difference between calling an async member method vs another class's async method. Moreover, where do you show the form (ie call mf.Show()? ) Commented Sep 30, 2013 at 6:46
  • BTW, what UI technology are you using? WinForms, WPF? Commented Sep 30, 2013 at 6:49

2 Answers 2

1

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:

Sign up to request clarification or add additional context in comments.

Comments

0

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.