디스크의 특정 파일을 읽고 쓰는 (그러나 동기식으로) 응용 프로그램을 개발하고 있습니다. 그러나 파일 가져 방법 클수록 더 자주 나는 IOException가 다음 얻을 :'사용자 매핑 섹션이 열려있는 파일에서 요청한 작업을 수행 할 수 없으면 어떻게됩니까?'
요청한 작업 오픈 사용자 매핑 섹션 파일을 수행 할 수 없습니다.
발생하는가에서 : 당신이 볼 수 있듯이
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options)
at System.IO.StreamWriter.CreateFile(String path, Boolean append)
at System.IO.StreamWriter..ctor(String path, Boolean append, Encoding encoding, Int32 bufferSize)
at System.IO.StreamWriter..ctor(String path, Boolean append, Encoding encoding)
at System.IO.File.WriteAllText(String path, String contents, Encoding encoding)
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at TestApp.Program.Main()
, 예외는 File.WriteAllText
내에서 발생합니다. 나는 예외가 동시 읽기 및 쓰기와 관련이 있다고 생각하여 파일에 대한 액세스를 제한하려고 시도했습니다. lock
과 Mutex
은 예외를 방지하는 대신 예외 수를 늘리는 것으로 보입니다. 무슨 일이 벌어지고 있니? 이 예외는 정확히 무엇을 의미하며 어떻게 예방할 수 있습니까?
내 상황에서도 이와 같았습니다. 문제의 원인이 정확히 어디인지, 문제를 방지해야하는지는 확실하지 않습니다. – dbaw