You'll also need to wait on the call to ListFoldersAsync. Otherwise the
work of dealing with the database may still be going on.
Either
var folders = await _adminService.ListFoldersAsync();
or, if you have to call this from a non-async context something like this
may work but will be less than optimal.
var tsk = _adminService.ListFoldersAsync();
tsk.Wait();
var folders = tsk.Result;
On Monday, September 17, 2018 at 9:18:22 AM UTC-4, Đạt Ý Đặng Huỳnh wrote:
>
> Hi everyone! I am working on a project using NHibernate v.4 and i want to
> upgrade to v.5 to so that i can use Asynchonous function.But when i use
> async in my code, it doesnt return any result and stucked in await block.
> Here is my code without async
> public List<Folder> ListFolders()
> {
> var folders = new List<Folder>();
>
> var hashtableFolders =
> ContextPerRequest.Session.CreateCriteria(typeof(Folder).Name)
> .Add(Restrictions.Eq("State",
> (int)State.Active))
> .List<Hashtable>();
>
> foreach (var hashtableFolder in hashtableFolders)
> {
> var folder =
> _hashtableAdapter.HashtableToObject<Folder>(hashtableFolder);
> folders.Add(folder);
> }
>
> return folders;
> }
>
> And here is my code use async
> public async Task<List<Folder>> ListFoldersAsync()
> {
> var folders = new List<Folder>();
>
> var hashtableFolders = await
> ContextPerRequest.Session.CreateCriteria(typeof(Folder).Name)
> .Add(Restrictions.Eq("State",
> (int)State.Active))
> .ListAsync<Hashtable>();
>
> foreach (var hashtableFolder in hashtableFolders)
> {
> var folder =
> _hashtableAdapter.HashtableToObject<Folder>(hashtableFolder);
> folders.Add(folder);
> }
>
> return folders;
> }
>
> And its usage
> var folders = _adminService.ListFoldersAsync().Result;
> Please help. Thanks you!
>
--
You received this message because you are subscribed to the Google Groups
"nhusers" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/nhusers.
For more options, visit https://groups.google.com/d/optout.