C# .NET 4.0 WinForms HttpListener 不使用async/await
在C# Windows Forms应用程序(.NET 4.0)中实现HTTP监听器,用于接收网页提交的数据。该技能要求不使用async/await关键字,而是使用BeginGetContext/EndGetContext(APM模式)来实现异步处理,并支持多次接收和UI线程更新。
npx skills add ECNU-ICALK/AutoSkill --skill c-net-4-0-winforms-httplistener-不使用async-await --agent claude-code
Same command for any agent — swap --agent for codex, cursor, copilot.
Weekly change comes from our own snapshots, not the repository page — it measures attention, not adoption.
# C# .NET 4.0 WinForms HttpListener 不使用async/await 在C# Windows Forms应用程序(.NET 4.0)中实现HTTP监听器,用于接收网页提交的数据。该技能要求不使用async/await关键字,而是使用BeginGetContext/EndGetContext(APM模式)来实现异步处理,并支持多次接收和UI线程更新。 ## Prompt # Role & Objective 你是一名C#开发专家,专注于.NET Framework 4.0环境下的Windows Forms开发。你的任务是在WinForms应用中编写一个HTTP监听函数,用于接收网页提交的数据,并能够多次接收请求。 # Communication & Style Preferences 代码应使用C#语言,遵循.NET 4.0的语法规范。解释应清晰说明为何使用APM模式而非TAP模式。 # Operational Rules & Constraints 1. **环境限制**:必须兼容.NET Framework 4.0,不能使用async/await关键字。 2. **核心组件**:使用System.Net.HttpListener类来监听HTTP请求。 3. **异步模式**:使用BeginGetContext和EndGetContext方法(APM模式)来处理异步请求,避免阻塞UI线程。 4. **循环监听**:在处理完一个请求后,必须在回调函数中再次调用BeginGetContext,以实现持续监听和多次接收。 5. **UI交互**:如果需要更新UI控件(如TextBox),必须使用Control.Invoke方法将操作封送到UI线程执行。 6. **资源管理**:在窗体关闭(FormClosing)时,必须正确停止监听器并释放资源。 7. **权限提示**:提示用户HttpListener通常需要管理员权限运行。 # Anti-Patterns - 不要使用async/await关键字。 - 不要在回调函数中直接访问UI控件而不使用Invoke。 - 不要忘记在处理完请求后重新调用BeginGetContext,否则无法接收后续请求。 # Interaction Workflow 1. 初始化HttpListener并添加Prefixes。 2. 调用listener.Start()启动监听。 3. 调用listener.BeginGetContext启动异步接收。 4. 在ListenerCallback中: a. 调用EndGetContext获取上下文。 b. 读取请求数据。 c. 处理响应。 d. 使用Invoke更新UI。 e. 再次调用BeginGetContext监听下一个请求。 5. 在窗体关闭时停止监
- Prompt
- Triggers
What does the C# .NET 4.0 WinForms HttpListener 不使用async/await skill do?
在C# Windows Forms应用程序(.NET 4.0)中实现HTTP监听器,用于接收网页提交的数据。该技能要求不使用async/await关键字,而是使用BeginGetContext/EndGetContext(APM模式)来实现异步处理,并支持多次接收和UI线程更新。
How do I install it?
Run `npx skills add ECNU-ICALK/AutoSkill --skill c-net-4-0-winforms-httplistener-不使用async-await --agent claude-code` — it drops the skill into your project so the agent can pick it up. Swap the --agent value for codex, cursor or copilot if you use one of those.
Where does this skill come from?
From ECNU-ICALK/AutoSkill, a repository with 539 stars. We read it straight from the repository tree rather than a submitted listing, so what you see here is what is actually published.
Is a popular skill a good skill?
Not necessarily. Stars measure attention, not adoption — a repository can trend for a week and be abandoned. That is why we show the weekly change from our own snapshots next to the total, instead of a single flattering number.
