c# - Getter property with async method doesn't finish executing -
problem: method doesn't finish executing (no exception, http request in pending
status).
i have implement next interface:
public interface iqueryableuserstore<tuser, in tkey> : iuserstore<tuser, tkey>, idisposable tuser : class, iuser<tkey> { iqueryable<tuser> users { get; } }
i did this:
public iqueryable<user> users { { return (this._userrepository.getall().result).asqueryable(); } }
here getall()
implementation:
public async task<ienumerable<user>> getall() { const string query = @" select * [dbo].[user] "; return (await this._db.queryasync<user>(query, new {})); }
edit: remove async behavior method , method call , works. why shouldn't works async?
this works:
public iqueryable<user> getall() { const string query = @" select * [dbo].[user] "; return this._db.query<user>(query, new {}).asqueryable(); }
task.result
can cause deadlocks, explain on blog.
you need decide if want database access synchronous or asynchronous. if synchronous, go synchronous way:
public iqueryable<user> getall() { const string query = @" select * [dbo].[user] "; return this._db.query<user>(query, new {}).asqueryable(); }
if asynchronous, go asynchronous way:
public interface iqueryableuserstore<tuser, in tkey> : iuserstore<tuser, tkey>, idisposable tuser : class, iuser<tkey> { task<iqueryable<tuser>> getusers(); }
sync-over-async antipattern in vast majority of cases. talk more principle of async way in msdn article.
Comments
Post a Comment