zoukankan      html  css  js  c++  java
  • net 5 filter 异步版本


    直接上代码

    [TypeFilter(typeof(customAttribute))] public async Task<IActionResult>Index() { System.Console.WriteLine($"2222222222线程{Thread.CurrentThread.ManagedThreadId.ToString()}"); await Task.Run(() => { System.Console.WriteLine($"子线程{Thread.CurrentThread.ManagedThreadId.ToString()}"); Thread.Sleep(1000); _test.hello(); }); System.Console.WriteLine($"2222222222线程{Thread.CurrentThread.ManagedThreadId.ToString()}"); return Ok(); }






    ////
    customAttribute 类


    public class customAttribute:ActionFilterAttribute { public override async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next) { Console.WriteLine($"111111{ next.Method.Name.ToString()}"); var areaName = context.RouteData.Values["area"] + "/"; var controllerName = context.RouteData.Values["controller"] + "/"; string action = context.RouteData.Values["Action"].ToString(); string currentUrl = areaName + controllerName + action; Console.WriteLine($"111111{ currentUrl}线程{Thread.CurrentThread.ManagedThreadId.ToString()}"); var resultContext = await next(); // resultContext.Result is set. Console.WriteLine($"33333{ currentUrl}线程{Thread.CurrentThread.ManagedThreadId.ToString()}"); } }

    结果是 线程 可能是主线程也可能子线程

  • 相关阅读:
    visual studio 2013 生成依赖项关系图出错
    redHat 安装mono 错误
    redHat 安装mono 错误
    msdn帮助,离线下载
    w
    msdn帮助,离线下载
    vs2013 找不到帮助 help查看器
    vs2013 找不到帮助 help查看器
    c# wpf 加密文本
    c# wpf 加密文本
  • 原文地址:https://www.cnblogs.com/jasontarry/p/15325412.html
Copyright © 2011-2022 走看看