I am wrapping AspNet.Identity. But something bothers me about TPL.
First example:
public virtual async Task<IdentityResult> RemovePasswordAsync(string userId) { var user = _store.FindByIdAsync(userId).Result; if (user == null) throw new InstanceNotFoundException("user"); user.PasswordHash = String.Empty; user.SecurityStamp = String.Empty; return await UpdateAsync(user); } public virtual async Task<IdentityResult> UpdateAsync(TUser user) { await _store.UpdateAsync(user); return new IdentityResult(); }
Second example:
public virtual Task<IdentityResult> RemovePasswordAsync(string userId) { var user = _store.FindByIdAsync(userId).Result; if (user == null) throw new InstanceNotFoundException("user"); user.PasswordHash = String.Empty; user.SecurityStamp = String.Empty; return UpdateAsync(user); } public virtual async Task<IdentityResult> UpdateAsync(TUser user) { await _store.UpdateAsync(user); return new IdentityResult(); }
And the customer will call it as follows:
result = await _userManager.RemovePasswordAsync(user.Id);
My first question is:
When the client calls the second method, the work is unloaded into the threadpool stream from the I / O stream. And when RemovePasswordAsync is called, it calls UpdateAsync, which has a wait keyword. So, at this point is this threadpool thread unloaded into another thread thread? Or does TPL continue to use the same stream instead?
And my second question: what is the main difference between the first implementation and the second implementation of constructing this asynchronous method?
EDIT:
This is a method to update the UserStore class. (_store.UpdateAsync (user))
public Task UpdateAsync(TUser user) { if (user == null) throw new ArgumentNullException("user"); return _userService.UpdateAsync(user); }
And this is the method of updating the UserService class
public Task UpdateAsync(TUser user) { return Task.Factory.StartNew(() => Update(user)); }
Kemal gΓΌltekin
source share