相关疑难解决方法(0)

什么进程锁定文件?

我试图找出使用下面的类锁定文件的进程.这里出了什么问题?

呼叫:

private void button1_Click(object sender, EventArgs e)
{
   Console.WriteLine(Win32Processes.GetProcessesLockingFile("locked_file.dll").ToString());
}
Run Code Online (Sandbox Code Playgroud)

输出:

System.Collections.Generic.List`1 [的System.Diagnostics.Process]

使用此电话:

using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Diagnostics;
using System.Text;
using System.Threading;

namespace FileLockInfo {

    public class Win32Processes {

        /// <summary>
        /// Return a list of processes that hold on the given file.
        /// </summary>
        public static List<Process> GetProcessesLockingFile (string filePath) {
            var procs = new List<Process>();

            foreach (var process in Process.GetProcesses()) {
                var files = GetFilesLockedBy(process);
                if (files.Contains(filePath)) procs.Add(process);
            }
            return procs;
        }

        /// …
Run Code Online (Sandbox Code Playgroud)

.net c# process

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

标签 统计

.net ×1

c# ×1

process ×1