发布网友 发布时间:2022-04-19 13:53
共1个回答
热心网友 时间:2023-09-15 16:54
那么你干嘛要获取可用端口呢?追答不熟悉python的库
如果是C# 本身又isopen属性
还有系统调用:
[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
internal static extern SafeFileHandle CreateFile(string lpFileName, int dwDesiredAccess, int dwShareMode, IntPtr securityAttrs, int dwCreationDisposition, int dwFlagsAndAttributes, IntPtr hTemplateFile);
SafeFileHandle hFile = CreateFile(@"\\.\" + portName, -1073741824, 0, IntPtr.Zero, 3, dwFlagsAndAttributes, IntPtr.Zero);
if (hFile.IsInvalid)
//已经占用