随笔分类 -  .NET Standard

摘要:提问 多线程任务怎么选 Thread,ThreadPoll,Task 回答 Task 原因 Thread:创建销毁代价昂贵 ThreadPoll:管理线程资源 Task 基于线程池 阅读全文
posted @ 2023-04-04 09:57 东百牧码人 阅读(56) 评论(0) 推荐(0)
摘要:提问 如何让开发的命令行程序 回答 使用System.CommandLine脚手架让你的程序支持多种命令 参考 https://learn.microsoft.com/en-us/dotnet/standard/commandline/ 阅读全文
posted @ 2023-03-24 14:57 东百牧码人 阅读(9) 评论(0) 推荐(0)
摘要:提问 如何Linq左连接 回答 注意 into 推荐返回匿名类型 var query = from person in people join pet in pets on person equals pet.Owner into gj from subpet in gj.DefaultIfEmpt 阅读全文
posted @ 2023-03-23 14:28 东百牧码人 阅读(24) 评论(0) 推荐(0)
摘要:提问 C#如何进行并行任务 回答 最大并行书为系统CPU数 po.MaxDegreeOfParallelism = Environment.ProcessorCount; var po = new ParallelOptions(); po.MaxDegreeOfParallelism = Envi 阅读全文
posted @ 2023-03-22 08:56 东百牧码人 阅读(43) 评论(0) 推荐(0)
摘要:提问 如何buid自动升级版本 原因 在离线部署中为了构建版本可跟踪,只使用主版本、次版本、修订版是不够的,必须跟踪到每一次build; 解答 csproj文件增加 <PropertyGroup> <GenerateAssemblyInfo>false</GenerateAssemblyInfo> 阅读全文
posted @ 2023-03-20 13:17 东百牧码人 阅读(22) 评论(0) 推荐(0)
摘要:提问 应该为泛型提供约束吗 回答 应该 理由 ”约束“这个词可能会引起歧义,有些人可能认为对泛型参数设定约束是限制参数的使用,实际情况正好相反。没有约束的泛型参数作用很有限,倒是”约束“让泛型参数具有了更多的行为和属性。 public class Salary { /// <summary> /// 阅读全文
posted @ 2023-03-20 10:38 东百牧码人 阅读(14) 评论(0) 推荐(0)
摘要:提问 WebApi 单文件发布Serilog 失效怎么解决 回答 配置文件Appsetting.json增加Using块 "Using": [ "Serilog.Sinks.Console", "Serilog.Sinks.File" ], 示例 { "Serilog": { "Using": [ 阅读全文
posted @ 2023-03-17 10:45 东百牧码人 阅读(90) 评论(0) 推荐(1)
摘要:提问 如何优雅的时使用TryParse 回答 YES var d = double.TryParse("3.1415", out var value) ? value : 0, NO var value = 0d; var ok = double.TryParse("3.1415", out val 阅读全文
posted @ 2023-03-16 10:15 东百牧码人 阅读(23) 评论(0) 推荐(0)
摘要:提问 如何在没有构造函数初始化的情况下消除警告 回答 #pragma warning disable CS8618 阅读全文
posted @ 2023-03-03 09:35 东百牧码人 阅读(14) 评论(0) 推荐(0)
摘要:提问 如何使用Equals 回答 1.Equals(<可空变量>) 不要 <可空变量>.Equals(1) 阅读全文
posted @ 2023-03-03 08:47 东百牧码人 阅读(17) 评论(0) 推荐(0)
摘要:提问 如何Jenkins发布NetCore程序 回答 cd BluePig taskkill /F /im BluePig.exe nssm stop BluePig nssm remove BluePig confirm del /s /f /q publish dotnet restore do 阅读全文
posted @ 2023-02-14 09:39 东百牧码人 阅读(23) 评论(0) 推荐(0)
摘要:提问 设置服务恢复bat命令 回答 以管理员身份运行 sc.exe failure "服务名称" reset=0 actions=restart/60000/restart/60000/run/1000 参考 https://www.cnblogs.com/stoneniqiu/p/4788449. 阅读全文
posted @ 2023-02-02 08:51 东百牧码人 阅读(52) 评论(0) 推荐(0)
摘要:提问 C# 如何连接WebSocket服务 回答 引入nuget WebSocketSharp 连接服务 using ActiveAlarmDemo.Models; using Microsoft.Extensions.Hosting; using Newtonsoft.Json; using We 阅读全文
posted @ 2022-12-28 15:15 东百牧码人 阅读(776) 评论(0) 推荐(0)
摘要:提问 如何创建 .NET Core后台服务 回答 引入nuget Microsoft.Extensions.Hosting 创建服务 using ActiveAlarmDemo.Models; using Microsoft.Extensions.Hosting; namespace ActiveA 阅读全文
posted @ 2022-12-27 17:04 东百牧码人 阅读(137) 评论(0) 推荐(0)
摘要:提问 EF Core如创建sqlite表 回答 在项目根目录执行命令 dotnet tool install --global dotnet-ef dotnet add package Microsoft.EntityFrameworkCore.Design dotnet ef migrations 阅读全文
posted @ 2022-12-26 14:39 东百牧码人 阅读(64) 评论(0) 推荐(0)
摘要:提问 linq 如何使用left join? 回答 from v in list1 join c in list2 on v.[条件] equals c.[条件] select new 实体 { 属性赋值 } 注意 on后边条件顺序不能错 on和equals关键字的使用 参考 https://www 阅读全文
posted @ 2022-12-14 16:12 东百牧码人 阅读(38) 评论(0) 推荐(0)
摘要:命令 # .NET Core v2 # Build, test, package, or publish a dotnet application, or run a custom dotnet command. - task: DotNetCoreCLI@2 inputs: command: 'b 阅读全文
posted @ 2022-11-21 09:39 东百牧码人 阅读(389) 评论(0) 推荐(0)
摘要:提问 如何使用log4net 回答 配置 using log4net; using log4net.Config; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; na 阅读全文
posted @ 2022-11-03 13:50 东百牧码人 阅读(22) 评论(0) 推荐(0)
摘要:提问 如何切面记录日志 回答 使用MethodDecorator.Fody using System.Reflection; using my.Attributes; using my.Log4Net; using log4net; using MethodDecorator.Fody.Interf 阅读全文
posted @ 2022-11-01 14:43 东百牧码人 阅读(66) 评论(0) 推荐(0)
摘要:提问 如何获取当前程序集 回答 var assembly = Assembly.GetExecutingAssembly(); 阅读全文
posted @ 2022-11-01 09:29 东百牧码人 阅读(23) 评论(0) 推荐(0)