如何在C#中通过TCP发送Fire& Forget Post Request? (无需等待回复) [英] How to send Fire&Forget Post Request Over TCP in C#? (Without wait for response)

查看:31
本文介绍了如何在C#中通过TCP发送Fire& Forget Post Request? (无需等待回复)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述







解决方案

你好,


>>我希望尽快发送请求,因此即使在MILISOCONDS中也不应等待响应


如果您想尽快发送请求。您可以使用多线程技术,但创建线程也是一项耗时的操作。 HTTP通信基于tcp协议。 tcp协议正在​​
传输层工作。它将根据网速逐个发送请求包。换句话说,发送请求的速度受许多因素的影响。至于代码,优化的代码采用多线程。如下所示。

 //静态HttpWebRequest请求; 
static void Main(string [] args)
{

for(int j = 1; j< = 100; j ++)
{
new Thread(PostForm).Start();
}
Console.ReadKey();
}
private static void PostForm()
{
....
Console.WriteLine(" ID ==" + System.Threading.Thread。 CurrentThread.ManagedThreadId);
....

}

真诚地,


neil hu



解决方案

Hello,

>>i want to the requests send fast as possible, so they should not be wait for respond even in MILISOCONDS

if you want to send request as fast as possible . You could use the multithreading technology, but creating a thread is also a time-consuming operation. and The HTTP communicate is based on the tcp protocol . The tcp protocol  is working at a transport layer . It will send the request packet one by one base on the net speed. In other words, the speed of sending request is affected by many factors. As for the code , the optimized Code is take multi-threading . Something like below.

 //static HttpWebRequest request;
        static void Main(string[] args)
        {        

            for (int j = 1; j <= 100; j++)
            {
                new Thread(PostForm).Start();
            }      
            Console.ReadKey();       
        }
        private static void PostForm()
        {    
            ....
            Console.WriteLine("ID == " + System.Threading.Thread.CurrentThread.ManagedThreadId);
            ....
            
        }

Sincerely,

neil hu


这篇关于如何在C#中通过TCP发送Fire&amp; Forget Post Request? (无需等待回复)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆