今天我开始更多地研究HttpListener和它是什么,所以如果我对此或它的工作原理了解得不是很广泛,我道歉。但是当尝试使用Start()方法启动我的HttpListener时,我得到了这个异常:
Can't start the agent to listen transactionSystem.Net.HttpListenerException (32): The process cannot access the file because it is being used by another process.
这个异常也与前缀本身有关。
这是我正在使用的代码,这是我第三次重做,但我仍然得到相同的异常。
static void ListenTraces()
{
try
{
var httpListener = new HttpListener();
httpListener.Prefixes.Add("https://discord.com/");
try
{
httpListener.Start(); //this line is where the exception happens
}
catch (HttpListenerException hlex)
{
Console.WriteLine("Can't start the agent to listen transaction" + hlex);
return;
}
Console.WriteLine("Now ready to receive traces...");
while (true)
{
var context = httpListener.GetContext();
Console.WriteLine(context.Response);
}
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
}感谢所有帮助:)
发布于 2021-06-17 16:22:09
可能已经有其他东西在该端口上侦听(您是否有任何其他开发服务器正在运行?)
尝试通过更改注册表值将代理端口配置为其他端口。
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\MsDepSvc\Parameters\ListenUrl默认情况下,此值应为http://+:80/MSDEPLOYAGENTSERVICE/。你可以把80改成81。然后重新启动您的服务。
https://stackoverflow.com/questions/68011540
复制相似问题