首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >尝试在C#中启动HttpListener时的HttpListenerException

问尝试在C#中启动HttpListener时的HttpListenerException
EN

Stack Overflow用户
提问于 2021-06-17 08:43:26
回答 1查看 33关注 0票数 0

今天我开始更多地研究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.

这个异常也与前缀本身有关。

这是我正在使用的代码,这是我第三次重做,但我仍然得到相同的异常。

代码语言:javascript
复制
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());
            }
        }

感谢所有帮助:)

EN

回答 1

Stack Overflow用户

发布于 2021-06-17 16:22:09

可能已经有其他东西在该端口上侦听(您是否有任何其他开发服务器正在运行?)

尝试通过更改注册表值将代理端口配置为其他端口。

代码语言:javascript
复制
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\MsDepSvc\Parameters\ListenUrl

默认情况下,此值应为http://+:80/MSDEPLOYAGENTSERVICE/。你可以把80改成81。然后重新启动您的服务。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68011540

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档