sendasync

How to use Socket.SendAsync to send large data

雨燕双飞 提交于 2019-12-05 22:31:35
private void ProcessReceive(SocketAsyncEventArgs e) { // Check if the remote host closed the connection. if (e.BytesTransferred > 0) { if (e.SocketError == SocketError.Success) { Token token = e.UserToken as Token; token.SetData(e); Socket s = token.Connection; if (s.Available == 0) { Boolean willRaiseEvent = false; // GET DATA TO SEND byte[] sendBuffer = token.GetRetBuffer(); // this.bufferSize IS SocketAsyncEventArgs buffer SIZE byte[] tempBuffer = new byte[this.bufferSize]; int offset = 0; int size = (int)Math.Ceiling((double)sendBuffer.Length / (double)this.bufferSize); for (int i = 0; i <

ASP.NET MVC: Send email using SendAsync (System.Net.Mail)

血红的双手。 提交于 2019-12-05 00:43:25
问题 is there any way in MVC to get the System.Net.Mail SendAsync to work, instead of the blocking Send method? I tried using it but hit the "Page starting an asynchronous operation has to have the Async attribute" error, which I obviously can't resolve (or can I?) because there is no ASPX page with an @Page directive where I could add the Async attribute. Help is greatly appreciated :( 回答1: It looks like you want Asynchronous support for ASP.NET MVC. See also "Extend ASP.NET MVC for Asynchronous

Intercept C# HttpClient GetAsync

耗尽温柔 提交于 2019-12-04 10:20:14
I have a web project (C#, MVC5 but no WebAPI) and a simple HTTP REST client that is calling an external REST service and acquires an accessToken etcing. I want to check the response from all my Get/PostAsync calls for statusCode 401 but I see that I can only override the SendAsync method when implementing the DelegatingHandler . class CustomDelegatingHandler : DelegatingHandler { async protected override Task<HttpResponseMessage> SendAsync( HttpRequestMessage request, CancellationToken cancellationToken) { HttpResponseMessage response = await base.SendAsync(request, cancellationToken); if

Dispose SmtpClient in SendComplete?

删除回忆录丶 提交于 2019-12-01 03:36:48
When I use SmtpClient's SendAsync to send email, how do I dispose the smtpclient instance correctly? Let's say: MailMessage mail = new System.Net.Mail.MailMessage() { Body = MailBody.ToString(), IsBodyHtml = true, From = new MailAddress(FromEmail, FromEmailTitle), Subject = MailSubject }; mail.To.Add(new MailAddress(i.Email, "")); SmtpClient sc = new SmtpClient(SmtpServerAddress); //Add SendAsyncCallback to SendCompleted sc.SendCompleted += new SendCompletedEventHandler(SendAsyncCallback); //using SmtpClient to make async send (Should I pass sc or mail into SendAsyncCallback?) sc.SendAsync