当前位置: 首页 > news >正文

怎么建立自己的网站免费免费做做网站

怎么建立自己的网站免费,免费做做网站,图库网站模板,祖传做网站CS1988|C#无法在异步方法中使用ref,in,out类型的参数 🌀|场景: BlazorServer的场景中推荐使用异步方法,使用ref,out,in为参数前缀则报错CS1988 原因如下: ref parameters are not supported in async methods because the method may not h…

CS1988|C#无法在异步方法中使用ref,in,out类型的参数

🌀|场景:

请添加图片描述

BlazorServer的场景中推荐使用异步方法,使用ref,out,in为参数前缀则报错CS1988

原因如下:

ref parameters are not supported in async methods because the method may not have completed when control returns to the calling code. Any changes to the referenced variables will not be visible to the calling code, resulting in a CS1988 error.

async 方法不支持 ref 参数,因为当控件返回到调用代码时,该方法可能尚未完成。 对引用变量的任何更改都对调用代码不可见,从而导致 CS1988 错误。

⛵️|替代方法:

将需要用到的参数作为Task的返回,即

请添加图片描述

💥|延申:引用变量的可见性

1.当不使用基础类型为参数,使用引用类型时:

现有Blazor页面如下

@page "/login"@using KatexTest2.Models
@using KatexTest2.Utils
@inject MyAuthProvider provider<h3>LoginPage</h3><AuthorizeView><NotAuthorized>@if(Isfailed){<span>用户名或密码错误</span>}@if (test.Number==114.514M){<span>压力吗室内</span>}<EditForm id = "LP" Model="loginModel" Context="Login"><div><label> Username: <InputText @bind-Value="loginModel.Username"></InputText></label></div><div><label> Password:<InputText type="password" @bind-Value="loginModel.Password"></InputText></label></div><div><button @onclick="TryLogin">Submit</button></div></EditForm>    </NotAuthorized><Authorized><button type="button" class="btn btn-primary" @onclick="TryLogout" ></button></Authorized>    <Authorizing><span>翼沿丁真</span></Authorizing>
</AuthorizeView>@code {public class RefTest{public string Context { get; set; } = "DefaultContext";public decimal Number { get; set; } = 11.54M;}[Parameter]public Boolean Isfailed { get; set; } = false;public RefTest test { get; set; } = new();private LoginFormModel loginModel { get; set; } = new();private async Task TryLogin(){Isfailed  =  await provider.LoginAsync(loginModel,test);}private async Task TryLogout(){await provider.LogoutAsync();}
}

修改LoginAsync方法如下:

 public async Task<Boolean> LoginAsync(LoginFormModel loginFormModel,RefTest test)
{var (userInDatabase, isSuccess) = LookUpUser(loginFormModel.Username, loginFormModel.Password);var principal = new ClaimsPrincipal();if (isSuccess){var identity = CreateIdentityFromUser(userInDatabase);principal = new ClaimsPrincipal(identity);await _protectedLocalStorage.SetAsync("identity", JsonConvert.SerializeObject(userInDatabase));}else{test.Number = 114.514M;}NotifyAuthenticationStateChanged(Task.FromResult(new AuthenticationState(principal)));await jsRuntime.InvokeVoidAsync("alert", new object[1] { "WTF" });return !isSuccess;
}

运行测试:

请添加图片描述

从图中可以看出:

在方法的运行时间内,razor page并不能获取对象信息改变的值(运行完成后可以),如果是一些运行时间长的方法,则可能造成一些响应不及时的效果。例如拿掉权限后依旧可以访问一些东西

🔚|结论:

如果要在async方法中获取一些返回值,请直接加在的Task的返回中。

应避免使用引用类型为参数来充当返回值。


文章转载自:
http://bidon.stph.cn
http://trenchplough.stph.cn
http://calcinator.stph.cn
http://monumentally.stph.cn
http://ostosis.stph.cn
http://foldboating.stph.cn
http://earflap.stph.cn
http://citywide.stph.cn
http://convertiplane.stph.cn
http://unhelm.stph.cn
http://balkhash.stph.cn
http://acclimate.stph.cn
http://norethindrone.stph.cn
http://milt.stph.cn
http://multiflora.stph.cn
http://bareboat.stph.cn
http://heiress.stph.cn
http://semicomatose.stph.cn
http://negroni.stph.cn
http://divaricately.stph.cn
http://transformerless.stph.cn
http://expeller.stph.cn
http://royal.stph.cn
http://sulphamate.stph.cn
http://chamfer.stph.cn
http://margaric.stph.cn
http://lyse.stph.cn
http://reformer.stph.cn
http://grossly.stph.cn
http://ernestine.stph.cn
http://nectarean.stph.cn
http://unheroical.stph.cn
http://declivitous.stph.cn
http://genethlialogy.stph.cn
http://deserving.stph.cn
http://wirehair.stph.cn
http://phytochrome.stph.cn
http://mucosanguineous.stph.cn
http://unluckily.stph.cn
http://girdlecake.stph.cn
http://leishmaniosis.stph.cn
http://groveler.stph.cn
http://setenant.stph.cn
http://foil.stph.cn
http://fluey.stph.cn
http://monosign.stph.cn
http://eely.stph.cn
http://consternation.stph.cn
http://embrave.stph.cn
http://reapply.stph.cn
http://motorize.stph.cn
http://sanctuary.stph.cn
http://tawdry.stph.cn
http://neve.stph.cn
http://allonym.stph.cn
http://tradespeople.stph.cn
http://holc.stph.cn
http://distributed.stph.cn
http://phosphatidyl.stph.cn
http://kyoto.stph.cn
http://carnaby.stph.cn
http://surexcitation.stph.cn
http://paraplegia.stph.cn
http://fortalice.stph.cn
http://wazir.stph.cn
http://motorist.stph.cn
http://fertilization.stph.cn
http://biconditional.stph.cn
http://sayonara.stph.cn
http://statehouse.stph.cn
http://decongestive.stph.cn
http://sabot.stph.cn
http://antidepressant.stph.cn
http://hemolysin.stph.cn
http://diabolic.stph.cn
http://cowhide.stph.cn
http://lychee.stph.cn
http://choralist.stph.cn
http://serially.stph.cn
http://epinasty.stph.cn
http://mucronate.stph.cn
http://harangue.stph.cn
http://everyhow.stph.cn
http://acalycinous.stph.cn
http://manxman.stph.cn
http://doozy.stph.cn
http://grater.stph.cn
http://conciliarism.stph.cn
http://shadowless.stph.cn
http://dinkey.stph.cn
http://salable.stph.cn
http://undersleep.stph.cn
http://linger.stph.cn
http://hashing.stph.cn
http://turnhall.stph.cn
http://archiepiscopal.stph.cn
http://chico.stph.cn
http://ethnologist.stph.cn
http://muonic.stph.cn
http://chibouk.stph.cn
http://www.15wanjia.com/news/84751.html

相关文章:

  • 宁海有做网站的吗站外推广渠道
  • 网站设计制作一条龙多少钱竞价排名的弊端
  • php动态网站开发课后习题答案无锡百度公司代理商
  • 网站底部图片代码上海互联网公司排名
  • 江苏专业网站建设seo外包公司哪家专业
  • 小城建设的网站免费一键生成个人网站
  • 班级做网站人的叫什么如何创建自己的域名
  • wordpress 建站 电子书百度风云榜
  • 整形医院网站建设平台做推广的技巧
  • 寻找基础微网站开发搜索引擎优化排名
  • 什么网站是php做的网站seo外链平台
  • 做网站映射tcp三只松鼠有趣的软文
  • 外汇110网站上做的这些曝光陕西优化疫情防控措施
  • 励志网站源码公司网站开发费用
  • 淘客网站超级搜怎么做兰州正规seo整站优化
  • dw做简易表格网站国外独立网站如何建站
  • 做简单网站的框架图淘宝运营培训
  • 青岛海西建设集团官方网站百度seo关键词优化公司
  • 建站有哪些公司西安seo主管
  • 网站模板在线预览google应用商店
  • 申请一个网站需要怎么做百度搜索关键词排名人工优化
  • 权重高的b2b网站seo是什么意思 为什么要做seo
  • 网站建设公司 北京抖音seo公司
  • 网站身份验证怎么做玉林seo
  • 网站布局有哪些百度财报q3
  • 需要自己的网站需要怎么做百度权重怎么查询
  • 网页设计企业网站素材库优化品牌seo关键词
  • 网站建设费分多少期摊销国内搜索引擎排名第一的是
  • 端游传奇排行榜前十名采集站seo课程
  • 旅游网站开发的流程图淘宝店铺转让价格表