gpt4 book ai didi

c# - 'the requested operation cannot be performed on a file with a user-mapped section open?' 时出了什么问题

转载 作者:太空狗 更新时间:2023-10-29 21:25:53 26 4
gpt4 key购买 nike

我正在开发一个应用程序,它对磁盘上的某个文件进行大量读写操作(但同步进行)。但是,文件越大,我就越经常收到以下 IOException:

The requested operation cannot be performed on a file with a user-mapped section open.

发生于:

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 中抛出的。我怀疑异常与同时读写有关,因此试图限制对该文件的访问。 lockMutex 似乎都增加了异常的数量而不是阻止它们。那么到底发生了什么?这个异常到底是什么意思,如何避免?

最佳答案

第一个解决方案是关闭防病毒软件。更好的是,您可以将该文件夹添加到防病毒软件的扫描异常(exception)列表中。

关于c# - 'the requested operation cannot be performed on a file with a user-mapped section open?' 时出了什么问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1047616/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com