【问题标题】:System.IO.IOException: The process cannot access the file 'C:\RDS\RDS.txt' because it is being used by another process [duplicate]System.IO.IOException:该进程无法访问文件'C:\ RDS \ RDS.txt',因为它正在被另一个进程使用[重复]
【发布时间】:2017-04-22 14:34:47
【问题描述】:

运行我的应用程序后,几分钟后我收到此错误消息。为什么?如果您能帮我解答,我将不胜感激。

这里是我的Form1的源代码:https://github.com/betimen/txtRDS/blob/master/Form1.cs

(错误消息)

See the end of this message for details on invoking 
just-in-time (JIT) debugging instead of this dialog box.
************** Exception Text **************
System.IO.IOException: The process cannot access the file 'C:\RDS\RDS.txt' because it is being used by another process.
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, Boolean useLongPath, Boolean checkHost)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
at System.IO.StreamWriter.CreateFile(String path, Boolean append, Boolean checkHost)
at System.IO.StreamWriter..ctor(String path, Boolean append, Encoding encoding, Int32 bufferSize, Boolean checkHost)
at System.IO.StreamWriter..ctor(String path)
at WindowsFormsApplication2.Form1.timer1_Tick(Object sender, EventArgs e)
at System.Windows.Forms.Timer.OnTick(EventArgs e)
at System.Windows.Forms.Timer.TimerNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
************** Loaded Assemblies **************
mscorlib
Assembly Version: 4.0.0.0
Win32 Version: 4.5.27.0 built by: FX453PREVIEWREL
CodeBase: file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/mscorlib.dll
----------------------------------------
txtRDS
Assembly Version: 1.0.0.0
Win32 Version: 1.0.0.0
CodeBase: file:///C:/Users/hevi%20sms/Downloads/txtRDS.exe
----------------------------------------
System.Windows.Forms
Assembly Version: 4.0.0.0
Win32 Version: 4.5.27.0 built by: FX453PREVIEWREL
CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Windows.Forms/v4.0_4.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
----------------------------------------
System
Assembly Version: 4.0.0.0
Win32 Version: 4.5.27.0 built by: FX453PREVIEWREL
 CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System/v4.0_4.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
System.Drawing
Assembly Version: 4.0.0.0
Win32 Version: 4.5.27.0 built by: FX453PREVIEWREL
CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Drawing/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
----------------------------------------
Accessibility
Assembly Version: 4.0.0.0
Win32 Version: 4.5.27.0 built by: FX453PREVIEWREL
CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/Accessibility/v4.0_4.0.0.0__b03f5f7f11d50a3a/Accessibility.dll
----------------------------------------
System.Configuration
Assembly Version: 4.0.0.0
Win32 Version: 4.5.27.0 built by: FX453PREVIEWREL
CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Configuration/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll
----------------------------------------
System.Xml
Assembly Version: 4.0.0.0
Win32 Version: 4.5.27.0 built by: FX453PREVIEWREL
CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Xml/v4.0_4.0.0.0__b77a5c561934e089/System.Xml.dll
----------------------------------------
************** JIT Debugging **************
To enable just-in-time (JIT) debugging, the .config file for this
application or computer (machine.config) must have the
jitDebugging value set in the system.windows.forms section.
The application must also be compiled with debugging
enabled.
For example:
<configuration>
<system.windows.forms jitDebugging="true" />
</configuration>
When JIT debugging is enabled, any unhandled exception
will be sent to the JIT debugger registered on the computer
rather than be handled by this dialog box.

【问题讨论】:

  • 你检查我的答案了吗?对你有帮助吗?
  • 是的,我看了你的回答,我忙于工作,现在无法回复你,我有空闲时间,我会在 1 秒内回复你的回答
  • 我目前无法阅读@SachithMW 的答案。有什么意见吗?

标签: c# forms


【解决方案1】:

您是否在另一个应用程序中打开了文本文件?听起来好像有一个程序打开了文本文件并阻止您的程序访问它。您可以通过以下方式找出哪个应用程序正在这样做:
http://www.techsupportalert.com/content/how-find-out-which-windows-process-using-file.htm

【讨论】:

  • 不,我没有在另一个应用程序中打开该文本文件。因为我知道如果我在记事本中打开该文本文件以检查 form1 的文本框文本是否已成功写入并保存,则计时器重置几秒钟后会引发错误。我之前测试过。应用程序正在保存到文本文件,textbox2 显示文本文件的内容,所以我不需要在记事本中打开。但应用程序应在计算机中 7/24 运行,不应关闭。因为文本文件默认每隔 10 秒保存一次 textbox1.text 或 textbox4.text 的数据。但在 1-2 小时后抛出错误。
  • 如果您打算每 10 秒写入同一个文件,并且该文件仅由您的单个应用程序在其整个运行时使用。在应用程序关闭之前保持文件打开而不关闭它可能会很好。这也应该可以解决您的问题。
  • 我明白,是的,它应该只是同一个文本文件。因为有一个设备可以读取该文本文件的内容。所以我需要使用“关闭”。我已经检查了您的链接,并且没有阻止访问的进程。我仍在“资源监视器”和“进程资源管理器”屏幕上等待
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-12-05
  • 1970-01-01
  • 1970-01-01
  • 2012-09-13
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多