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()}"); } }

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

  • 相关阅读:
    尾递归
    Appium环境搭建
    虚拟机与主机的相互访问,虚拟机访问外网
    Python
    npm i 安装
    redis过期键删除策略
    Redis的过期策略和内存淘汰机制
    redis的两种持久化方案
    JVM 方法内联
    进程/线程/协程
  • 原文地址:https://www.cnblogs.com/jasontarry/p/15325412.html
Copyright © 2011-2022 走看看