需要处置iformfile.openreadstream()?

问题描述 投票:0回答:2
会处理?

Https://learn.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.http.ibroverfile.openreadstream?view = aspnetcore-5.0#micrososoft_aspnet_aspnetcore_http_http_http_http_ibortfile_openreadstrearearreampreamstreamseam

    
	

每次称为def the the the the the the the the the the new

using每次称为: Https://github.com/dotnet/aspnetcore/blob/033b1fb1cf681ea95d3954c08e4391c93cd72683/src/src/src/httppppp /http/http/src/src/src/src/formfile.cs.cs-cs,utl811,—

c#
2个回答
23
投票
不包含任何不受管理的资源。 打电话

FormFile

基本上是一个no-op。
Https://github.com/dotnet/aspnetcore/blob/033b1fb1cf681ea95d3954c08e4391c93cd72683/src/src/htttp/httpp/
考虑到这一点,不需要处理。  但是处理它也不会伤害任何事情。
    
ReferenceReadStream不会创建新的“流”;但是,它确实创建了一个新的

OpenReadStream()

,其中基础流被重复使用。我会使用

ReferenceReadStream
,因为
Dispose
没有实现,然后关闭流。 IFormFile.OpenReadStream()

Https://github.com/dotnet/aspnetcore/blob/033b1fb1cf681ea95d3954c08e4391c93cd72683/src/src/src/httppppp /http/http/src/src/src/src/formfile.cs.cs-cs,utl811,—


我的2cts在这里:此页面上的答案和评论似乎很集中在

默认实现的方面。

0
投票
=>

tl; dr:我建议使用

OpenReadStream()
语句或块包装
aLways
,如果只是因为有一天它可能是唯一要做的事情

    
	

最新问题
© www.soinside.com 2019 - 2024. All rights reserved.