agentsclimarketplace

C net 4 0 winforms httplistener 不使用async await

Skill ECNU-ICALK/AutoSkill/SkillBank/ConvSkill/chinese_gpt4_8/c-net-4-0-winforms-httplistener-不使用async-await

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

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

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

One thing to look at

  • no licenseNo license file was found in the repository. Code published without one is not open source by default, so using it at work is a question for whoever answers licensing questions where you are.

SKILL.md

3.0 KB, 710 tokens by cl100k_base, as published. Nobody here has run it

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

What ships with it

Read from the repository

Just SKILL.md. No reference files, no scripts.

Keep looking

Skills are one crate of 325,949. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.