System.Net.HttpListenerResponse.Close C# (CSharp) Method

Close() public method

public Close ( byte responseEntity, bool willBlock ) : void
responseEntity byte
willBlock bool
return void
        public void Close(byte[] responseEntity, bool willBlock)
        {
            if (NetEventSource.IsEnabled) NetEventSource.Enter(this, $"responseEntity={responseEntity},willBlock={willBlock}");
            try
            {
                CheckDisposed();
                if (responseEntity == null)
                {
                    throw new ArgumentNullException(nameof(responseEntity));
                }
                if (NetEventSource.IsEnabled) NetEventSource.Info(this, $"ResponseState:{_responseState}, BoundaryType:{_boundaryType}, ContentLength:{_contentLength}");
                if (_responseState < ResponseState.SentHeaders && _boundaryType != BoundaryType.Chunked)
                {
                    ContentLength64 = responseEntity.Length;
                }
                EnsureResponseStream();
                if (willBlock)
                {
                    try
                    {
                        _responseStream.Write(responseEntity, 0, responseEntity.Length);
                    }
                    catch (Win32Exception)
                    {
                    }
                    finally
                    {
                        _responseStream.Close();
                        _responseState = ResponseState.Closed;
                        HttpListenerContext.Close();
                    }
                }
                else
                {
                    _responseStream.BeginWrite(responseEntity, 0, responseEntity.Length, new AsyncCallback(NonBlockingCloseCallback), null);
                }
            }
            finally
            {
                if (NetEventSource.IsEnabled) NetEventSource.Exit(this);
            }
        }

Same methods

HttpListenerResponse::Close ( ) : void

Usage Example

Esempio n. 1
0
		public void Process(HttpListenerRequest request, HttpListenerResponse response)
		{
			try
			{
				if (request.HttpMethod != "GET")
				{
					response.StatusCode = 405;
					response.StatusDescription = "Method Not Supported";
					response.Close();
					return;
				}

				string version = FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location).ProductVersion;
				string status = GetStatusDescription();
				string timestamp = DateTime.UtcNow.ToString("s", CultureInfo.InvariantCulture) + "Z";

				FormatJsonResponse(response, version, status, timestamp);
			}
			catch (HttpListenerException hlex)
			{
				Supervisor.LogException(hlex, TraceEventType.Error, request.RawUrl);

				response.StatusCode = 500;
				response.StatusDescription = "Error Occurred";
				response.Close();
			}
		}
All Usage Examples Of System.Net.HttpListenerResponse::Close