Skip to content
Back to skills

C Net 4 0 Winforms Httplistener 不使用Async Await

ASecurity

在C# Windows Forms应用程序(.NET 4.0)中实现HTTP监听器,用于接收网页提交的数据。该技能要求不使用async/await关键字,而是使用BeginGetContext/EndGetContext(APM模式)来实现异步处理,并支持多次接收和UI线程更新。

  • 611 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added November 11, 2026
educationc#

Security analysis

A100/100

Scanned November 11, 2026

npx -y skills add ECNU-ICALK/AutoSkill --skill 'c-net-4-0-winforms-httplistener-不使用async-await' --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of C Net 4 0 Winforms Httplistener 不使用Async Await?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for C Net 4 0 Winforms Httplistener 不使用Async Await
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/ecnu-icalk-c-net-4-0-winforms-httplistener-async-await/badge)](https://www.skillsdirectory.com/skills/ecnu-icalk-c-net-4-0-winforms-httplistener-async-await)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
id: "366cb268-139e-47cb-bc99-f9443ff4d21c"
name: "C# .NET 4.0 WinForms HttpListener 不使用async/await"
description: "在C# Windows Forms应用程序(.NET 4.0)中实现HTTP监听器,用于接收网页提交的数据。该技能要求不使用async/await关键字,而是使用BeginGetContext/EndGetContext(APM模式)来实现异步处理,并支持多次接收和UI线程更新。"
version: "0.1.0"
tags:
  - "C#"
  - ".NET4.0"
  - "HttpListener"
  - "WinForms"
  - "APM"
triggers:
  - "C# .net4.0 写一个监听函数"
  - "Windows Forms HttpListener 不用async"
  - ".net4.0 接收网页数据"
  - "BeginGetContext EndGetContext 示例"
  - "C# 监听HTTP请求 不使用async"
---

# 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. 在窗体关闭时停止监听。

## Triggers

- C# .net4.0 写一个监听函数
- Windows Forms HttpListener 不用async
- .net4.0 接收网页数据
- BeginGetContext EndGetContext 示例
- C# 监听HTTP请求 不使用async

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in education →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.