我有一个形式为的类构造函数:
protected LoginFunctions(){â¦..}
在此函数中,我使用以下方法调用异步函数:
var tsk = Task.Run(async () => await PrePopulateLogin());
我的问题是,当构造函数退出时,预填充登录函数仍在运行。如何更改我的代码,使构造函数在预填充登录完成后才退出?
预填充登录必须是异步的。
private async Task PrePopulateLogin()
{
var vector = await JSRuntime.Current.InvokeAsync("blazorExtensions.ReadCookie", "vector");
var secureNextLogon = await JSRuntime.Current.InvokeAsync("blazorExtensions.ReadCookie", "SecureNextLogon");
if (secureNextLogon != null)
{
var encryptor = new AesEncryptor(SecurityConstants.SecurityKey, Convert.FromBase64String(vector));
var decryptedValue = encryptor.Decrypt(secureNextLogon);
var email = decryptedValue.Split(' ')[0].Substring(6);
var password = decryptedValue.Split(' ')[1].Substring(9);
var rememberMe = decryptedValue.Split(' ')[2].Substring(11);
if (rememberMe == "True")
{
UserModel.EmailAddress = email;
UserModel.Password = password;
UserModel.RememberUser = true;
}
}
}