我试图找出使用下面的类锁定文件的进程.这里出了什么问题?
呼叫:
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)