标签: locked-files

错误:无法访问文件bin/Debug/...因为它正由另一个进程使用

当我调试我的项目时,我收到以下错误:

"无法将文件"obj\Debug\My Dream.exe"复制到"bin\Debug\My Dream.exe".进程无法访问文件'bin\Debug\My Dream.exe',因为它正被另一个人使用处理."

使用Process Explorer,我看到MyApplication.exe已经关闭但系统进程仍然使用它,尽管我之前停止了调试.每当我更改代码并开始调试时,它都会发生.如果我将项目复制到USB并进行调试,它运行正常.

为什么?我该如何解决这个错误?

我使用Window 7 Professional.使用Xp我从未遇到过这个错误.

debugging projects-and-solutions locked-files visual-studio

106
推荐指数
6
解决办法
11万
查看次数

SMTP发送锁定了我的文件 - c#

我有一个功能,发送消息(很多)和他们的附件.

它基本上循环遍历目录结构,并从文件结构创建电子邮件

 c:\emails\message01
                \attachments
 c:\emails\message02
                \attachments
Run Code Online (Sandbox Code Playgroud)

使用.net c#,标准内容创建消息.

创建所有消息后......我有另一个直接运行的函数,它将消息文件夹复制到另一个位置.

问题是 - 文件被锁定了......

注意:我没有移动文件,只是复制它们....

有关如何使用c#复制锁定文件的任何建议?

更新

我有这个添加附件方法

    private void AddAttachments(MailMessage mail)
    {
        string attachmentDirectoryPath = "c:\messages\message1";
        DirectoryInfo attachmentDirectory = new DirectoryInfo(attachmentDirectoryPath);
        FileInfo[] attachments = attachmentDirectory.GetFiles();
        foreach (FileInfo attachment in attachments)
        {
            mail.Attachments.Add(new Attachment(attachment.FullName));
        }
    }
Run Code Online (Sandbox Code Playgroud)

c# smtp locked-files

23
推荐指数
2
解决办法
1万
查看次数

将文件作为附件发送后锁定文件

我发送文件作为附件:

            // Create  the file attachment for this e-mail message.
            Attachment data = new Attachment(filePath, MediaTypeNames.Application.Octet);
            // Add time stamp information for the file.
            ContentDisposition disposition = data.ContentDisposition;
            disposition.CreationDate = System.IO.File.GetCreationTime(filePath);
            disposition.ModificationDate = System.IO.File.GetLastWriteTime(filePath);
            disposition.ReadDate = System.IO.File.GetLastAccessTime(filePath);
            // Add the file attachment to this e-mail message.
            message.Attachments.Add(data);
Run Code Online (Sandbox Code Playgroud)

然后我想将文件移动到另一个文件夹,但是当我尝试这样做时

                    try
                    {
                        //File.Open(oldFullPath, FileMode.Open, FileAccess.ReadWrite,FileShare.ReadWrite);
                        File.Move(oldFullPath, newFullPath);

                    }
                    catch (Exception ex)
                    {
                    }
Run Code Online (Sandbox Code Playgroud)

它抛出了一个异常,即该文件已在另一个进程中使用.如何解锁此文件以便将其移动到此位置?

c# attachment locked-files

13
推荐指数
4
解决办法
1万
查看次数

有没有办法从命令行处理锁定文件并释放它?

有没有办法检测指定文件夹中的锁定文件并通过命令行释放它们?

伪代码中的这样的东西:

for file in folder do
unlock file
Run Code Online (Sandbox Code Playgroud)

windows command-line locked-files

13
推荐指数
2
解决办法
3万
查看次数

文件被 Visual Studio 2019 锁定

我在 Visual Studio 中有一个奇怪的问题:

如果在调试过程中抛出未处理的异常,我将无法构建我的 C# 应用程序:

Unable to copy file "C:\Projects\A\bin\A.dll" to "..\..\bin\A.dll". 
  The process cannot access the file '..\..\bin\A.dll' because it is being used 
  by another process.

Could not copy "C:\Projects\A\bin\A.dll" to "..\..\bin\A.dll". 
  Exceeded retry count of 10. Failed. 
  The file is locked by: "Microsoft Visual Studio 2019 (14904)"
Run Code Online (Sandbox Code Playgroud)

是否有永久解决方案来解决这个奇怪的错误?(我目前唯一的解决方法是重新启动 Visual Studio)

我尝试过但对我不起作用的方法:

  • VS 菜单 -> 工具 -> 选项 -> 项目和解决方案 -> 构建和运行 -> 并将“并行构建的最大数量”设置为 1。
  • 停止杀毒软件
  • 启用应用程序体验服务(在 Windows 10 中未找到)
  • 取消勾选VS菜单->工具->选项->项目和解决方案->常规->允许并行项目初始化
  • 取消调试 -> 选项 -> …

c# locked-files visual-studio visual-studio-2019

7
推荐指数
2
解决办法
1万
查看次数

如何使用Python解锁锁定的文件和文件夹(mac)

在我的脚本的主要目的完成后,作为"清理",调用一个函数来递归查看每个文件夹并删除以预定的一组扩展名结尾的所有文件.

我在测试期间,发现一些文件扩展名在删除列表中的文件实际上会抛出一个错误:[Errno 1] Operation not permitted: '/location/of/locked/file.png.查看文件本身,它似乎是锁定(在Mac上).

  1. 我如何使用Python从每个文件/文件夹中删除锁定属性(如果存在),然后删除文件,如果它在扩展名中结束?
    优选地,这可以在下面的相同功能中完成,因为遍历输入目录需要很长时间 - 只需处理一次即可.
  2. 这如何影响Windows上脚本的完整性?
    我已经开始对它进行编程,使其在操作系统之间兼容,但是(据我所知),Windows上不存在锁定属性,就像它在mac上一样,并且可能导致未知的副作用.

REMOVE_FILETYPES = ('.png', '.jpg', '.jpeg', '.pdf')

def cleaner(currentPath):
  if not os.path.isdir(currentPath):
    if currentPath.endswith(REMOVE_FILETYPES) or os.path.basename(currentPath).startswith('.'):
      try:
        os.remove(currentPath)
        print('REMOVED: \"{removed}\"'.format(removed = currentPath))
      except BaseException as e:
        print('ERROR: Could not remove: \"{failed}\"'.format(failed = str(e)))
      finally:
        return True
    return False

  if all([cleaner(os.path.join(currentPath, file)) for file in os.listdir(currentPath)]):
    try:
      os.rmdir(currentPath)
      print('REMOVED: \"{removed}\"'.format(removed = currentPath))
    except:
      print('ERROR: Could not remove: \"{failed}\"'.format(failed = currentPath))
    finally:
      return True …
Run Code Online (Sandbox Code Playgroud)

python macos locked-files python-3.x

5
推荐指数
1
解决办法
1290
查看次数

程序运行时,在创建文件后锁定目录

在目录中创建文件后,只要我创建文件的程序正在运行,目录就会被锁定.有没有办法释放锁?我需要稍后重命名该行目录,我总是得到IOException一句"访问路径"......"拒绝".

Directory.CreateDirectory(dstPath);
File.Copy(srcPath + "\\File1.txt", dstPath + "\\File1.txt"); // no lock yet
File.Create(dstPath + "\\" + "File2.txt"); // causes lock
Run Code Online (Sandbox Code Playgroud)

c# directory locked-files

3
推荐指数
1
解决办法
1017
查看次数

Azure Devops:如何使用“IIS Web 应用程序部署”任务启用重命名锁定文件 (RenameFilesFlag)

当我尝试在 Azure Devops 中使用发布管道进行部署时,我遇到了锁定 DLL 文件的问题。

错误的截图是:

在此输入图像描述

输出为文本:

2021-03-31T17:43:18.2626492Z ##[error]Error Code: ERROR_FILE_IN_USE
More Information: Web Deploy cannot modify the file 'Microsoft.Data.SqlClient.SNI.x64.dll' on the destination because it is locked by an external process.  In order to allow the publish operation to succeed, you may need to either restart your application to release the lock, or use the AppOffline rule handler for .Net applications on your next publish attempt.  Learn more at: http://go.microsoft.com/fwlink/?LinkId=221672#ERROR_FILE_IN_USE.
    Error count: 1.
Run Code Online (Sandbox Code Playgroud)

该问题似乎是由错误处置的 .NET 资源引起的。(例如:非托管 SqlConnection)无论如何,我无法更改源代码。

这是我的发布管道。

Azure DevOps 发布部署

这是我的问题: …

azure locked-files azure-devops azure-pipelines-release-pipeline

1
推荐指数
1
解决办法
2706
查看次数