6
我有一個返回PrivateFontCollection功能:.NET PrivateFontCollection - 如何釋放文件鎖完成後
Public Shared Function GetCustomFonts() As PrivateFontCollection
Dim result = New PrivateFontCollection
Dim customFontFiles = {"Garamond.TTF", "Garamond-Bold.TTF", "Garamond-Italic.TTF", "EurostileExtended-Roman-DTC.TTF"}
For Each fontFile In customFontFiles
result.AddFontFile(Hosting.HostingEnvironment.MapPath("/Includes/" & fontFile))
Next
Return result
End Function
我然後使用功能如下:
Using customFonts = Common.GetCustomFonts()
' Do some stuff here
End Using
我會想到的是,文件將被釋放,但它們仍然被鎖定:我得到以下錯誤:'該操作無法完成,因爲該文件在系統中打開。關閉文件並重試。'
在IIS中關閉網站並沒有幫助;我們必須回收應用程序池才能發佈。
任何人都可以建議如何使用PrivateFontCollection這樣的文件發佈inbetween使用?
我到目前爲止唯一的想法是將字體加載到內存中並使用AddMemoryFont代替。這樣我可以保證PrivateFontCollection永遠不會觸及文件。 – extremeandy 2014-10-29 23:12:14
對於可能的答案看看http://stackoverflow.com/questions/26671026/how-to-delete-the-file-of-a-privatefontcollection-addfontfile – Horcrux7 2014-10-31 13:35:42
添加連接錯誤https://connect.microsoft.com/ VisualStudio中/反饋/信息/ 1379843 – Peter 2015-05-29 14:00:50