04 2022 档案
摘要:core 2.0中通过实现IHostedService接口实现后台任务 public interface IHostedService { Task StartAsync(CancellationToken cancellationToken); Task StopAsync(Cancellatio
阅读全文
摘要:一般来说,WebApi返回数据需要封装为固定格式,比如state、message、data三个属性,state返回状态,为true或false(也可用status返回状态码),message返回消息,如操作失败的异常信息,data用来返回操作结果。 /// <summary> /// 操作结果封装
阅读全文
摘要:在 Asp.Net Core WebApi中,使用方法过滤器拦截请求和响应,对请求和响应的内容进行日志记录,详见代码: using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Controllers; using Microsof
阅读全文
摘要:async和await是C# 5.0新增加的关键字,提高了异步编程的易用性,请看以下示例: using System; using System.Diagnostics; using System.Threading; using System.Threading.Tasks; namespace
阅读全文