I used the CreateText method to create an empty file (as shown below) in "App1". Then I tried to write another application to this file, but it failed b / c, it was blocked. It was not unlocked until I closed "App1"
File.CreateText(path)
To fix this, I can do this:
Dim sw As StreamWriter = File.CreateText(path) sw.Close()
Why does calling only CreateText lock the file? Is there any implicit stream or script file or something created?
tep
Yes Yes. CreateText()returns the object StreamWriterthat is open for the file you specified.
CreateText()
StreamWriter
, StreamWriter , . , .
- ?
StreamWriter, . StreamWriter.
:
File.CreateText(path).Close()
.
CreateText() , StreamWriter, , .
, ( ).
, :
File.WriteAllBytes(path, new byte[0]);
File.CreateFile StreamWriter FileStream, FileMode.Create, FileAccess.Write FileShare.Read. , . , , , . , , , .
, , , File.CreateFile(). FileStream (Create, Write FileShared.ReadWrite) StreamWriter. , .
, , - . , , , . , .
, - , . , . , . , , , , .
, StreamWriter. . . .
, - -, .
Module Tools Sub CreateTextNoLock(ByVal text as String) Dim sw = File.CreateText(text) sw.Close End Sub End Module
StreamWriter , close. ( ), "" GC.
Using sw As StreamWriter = File.CreateText(path) sw.Write("") End Using
Source: https://habr.com/ru/post/1731119/More articles:ObjectDataSource does not call the Insert method when it has additional parameters - asp.netAsk JavaScript to calculate in the text box, not the popup! - javascriptC C ++ array .... need help understanding the code - c ++Visual Studio 2008 indented C comment / * * / - commentsКак прокси-сервер сеанса Facebook повышает безопасность? - securityAre there any code coverage tools that can only tell me about the code that I wrote during my last sprint? - javaPragmatism or purity. Should we rely on the GUI infrastructure to store the state of the program? - designHow to deploy a firewall application on Mac? - javacreation of the Mac OSX installer, so the installed application will not install the firewall - installerCan I clear the ASP.NET application cache without resetting AppDomain? - cachingAll Articles