c# - EntityFramework (6) and async ( waitingForActivation)? -


i've downloaded ef6 ( in order use async)

so wrote simple method :

  public async task<list<int>> myasyncmethod()       {           var locations = await mydumpentities.agegroups.select(f=>f.endyear).tolistasync();           return locations;        }     ...later...     dumpentities1 mydumpentities = new dumpentities1();   var data = mydumpentities.agegroups.tolistasync();   myasyncmethod().continuewith(s => { response.write("f"); });   mydumpentities.dispose(); 

but don't see on screen , when inspect data see :

enter image description here

p.s. tolistasync signature enter image description here

what missing ?

basing of off comments , line have problem with:

var data = mydumpentities.agegroups.tolistasync(); 

what data type be? task<list<agegroup>>. that's right, not list<agegroup>. so, either have mark page_load async (if possible):

public async void page_load(object sender, eventargs e) {     using(var mydumpentities = new dumpentities1())     {        var data = await mydumpentities.agegroups.tolistasync();     }      } 

or wait execution somehow (continuation, blocking wait).

another thing (someone else might want correct if i'm wrong), since you're using continuation second call, careful of disposing context outside of continuation. might turn out dispose context preemptively. in particular case, you're not using context in continuation, looks suspicious...

so i'd either

myasyncmethod().continuewith(s => { response.write("f"); mydumpentities.dispose();}); 

or use async there too

var result = await myasyncmethod(); response.write("f"); mydumpentities.dispose(); 

and add async="true" page directive


Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -