随笔- 672
文章- 2
评论- 325
阅读-
281万
随笔分类 - .Net Core
.NET Core版本兼容问题(链接)
摘要:下面的文章,很好地阐述了.NET Core各个版本之间的兼容问题: Is .NET Core Runtime backwards compatible with previous releases?
阅读全文
TransactionScope and database connections(转载)
摘要:问 Do TransactionScope work with closed database connections? using (var transaction = new TransactionScope(TransactionScopeOption.Required)) { // crea
阅读全文
Async/Await模式中使用TransactionScope时,要设置参数为TransactionScopeAsyncFlowOption.Enabled枚举(转载)
摘要:TransactionScope and Async/Await. Be one with the flow! You might not know this, but the 4.5.0 version of the .NET Framework contains a serious bug re
阅读全文
Does disposing StreamReader or StreamWriter close the stream?(转载)
摘要:问 I am sending a stream to methods to write on, and in those methods I am using a binary reader/wrtier. When the reader/writer gets disposed, either b
阅读全文
使用自定义的行分隔符,从StreamReader中读取一行字符串
摘要:在C#中,StreamReader的ReadLine方法是不支持自定义行分隔符的。这导致很多文本文件的行分隔符如果不是"\r"和"\n",那么使用StreamReader就无法正确读取到一行字符串。 所以我们这里采用一个.NET Core控制台项目,自定义一个ReadLineWithDelimite
阅读全文
SQL Server和C#中无法将小数字符串直接转换为整数类型
摘要:有时候我们会将一个小数字符串转换为整数,例如将"31.0"转换为整数类型,因为这个小数本来就是一个整数,它的小数位为0。 SQL Server 如果我们在SQL Server中直接将字符串'31.0'转换为INT类型,会报错: DECLARE @text NVARCHAR(50)=N'31.0' S
阅读全文
Is default(CancellationToken) equivalent to CancellationToken.None?(转载)
摘要:问 Looking at the implementation of CancellationToken.None, it is simply returning default(CancellationToken). However, I see no reference in Cancellat
阅读全文
关于TransactionScope.Complete方法(链接)
摘要:相信有些同学会困扰,当我们执行TransactionScope.Complete()方法的时候,是否Transaction被真正提交到数据库了。 对于这一点,MSDN上有这么一段描述: If the TransactionScope object created the transaction in
阅读全文
Do I need to dispose of Tasks?(链接)
摘要:Do I need to dispose of Tasks? Here’s my short answer to this question: “No. Don’t bother disposing of your tasks.”
阅读全文
为什么C#接口中不能声明async异步函数(转载)
摘要:Unable to declare Interface “ async Task<myObject> MyMethod(Object myObj); ” 问 I'm unable to declare interface IMyInterface { async Task<myObject> MyM
阅读全文
How does SqlDataReader handle really large queries?(转载)
摘要:问 Actually I'm not sure the title accurately describes the question, but I hope it is close enough. I have some code that performs a SELECT from a dat
阅读全文
ASP.NET Core MVC中的Filter如果不实现IFilterFactory接口,那么Filter默认情况下在ASP.NET Core生命周期内是单例的,会被重用
摘要:问 I have an AuthorizationFilter as follows: I found the constructor of AuthorizationFilter will just be called one time during the whole ASP.NET Core
阅读全文
What is the use for Task.FromResult<TResult> in C#(转载)
摘要:问: In C# and TPL (Task Parallel Library), the Task class represents an ongoing work that produces a value of type T.I'd like to know what is the need
阅读全文
await Task.Yield()和await Task.CompletedTask有什么不同
摘要:有时候我们在代码中要执行一些非常耗时的操作,我们不希望这些操作阻塞调用线程(主线程)的执行,因为调用线程(主线程)可能还有更重要的工作要做,我们希望将这些非常耗时的操作由另外一个线程去执行,这个时候就可以用到await Task.Yield(),它借助了C# 5.0中的异步函数关键字await as
阅读全文
Whats the benefit of passing a CancellationToken as a parameter to Task.Run?(转载)
摘要:问: Obviously I realize it enables me to cancel the task, but this code achieves the same effect without having to pass the token into Task.RunWhat is
阅读全文
利用.NET Core中的Worker Service,来创建windows服务或linux守护程序
摘要:导航 开始创建worker service 项目 Program.cs Worker.cs 依赖注入(DI) 重写BackgroundService类的StartAsync、ExecuteAsync、StopAsync方法 不要让线程阻塞worker类中重写的StartAsync、ExecuteAs
阅读全文
C#: Thread.Sleep vs. Task.Delay (转载)
摘要:We can use both Thread.Sleep() and Task.Delay() to suspend the execution of a program (thread) for a given timespan. But are we actually suspending th
阅读全文
C#中如何使用异步lambda表达式来初始化委托实例
摘要:下面我们通过一个.NET Core控制台项目,来展示如何使用异步lambda表达式来初始化三种委托实例:Func<Task<TResult>>、Func<Task>、Action 我们还展示了如何将Main函数改造为异步函数。 希望上面的例子对大家有所帮助~
阅读全文