WebResponse.Close Metod

Definition

När den åsidosätts av en underordnad klass stänger svarsströmmen.

public:
 virtual void Close();
public virtual void Close();
abstract member Close : unit -> unit
override this.Close : unit -> unit
Public Overridable Sub Close ()

Undantag

Alla försök görs att komma åt metoden, när metoden inte åsidosättas i en underordnad klass.

Exempel

I följande exempel används Close metoden för att stänga WebResponse.

// Create a 'WebRequest' object with the specified url. 	
WebRequest myWebRequest = WebRequest.Create("http://www.contoso.com"); 
// Send the 'WebRequest' and wait for response.	
WebResponse myWebResponse = myWebRequest.GetResponse(); 

// Process the response here.
Console.WriteLine("\nResponse Received.Trying to Close the response stream..");
// Release resources of response object.
myWebResponse.Close();
Console.WriteLine("\nResponse Stream successfully closed");
' Create a 'WebRequest' object with the specified url 	
Dim myWebRequest As WebRequest = WebRequest.Create("www.contoso.com")
' Send the 'WebRequest' and wait for response.	
Dim myWebResponse As WebResponse = myWebRequest.GetResponse()

'  Process the response here
Console.WriteLine(ControlChars.Cr + "Response Received.Trying to Close the response stream..")
' Release resources of response object
myWebResponse.Close()
Console.WriteLine(ControlChars.Cr + "Response Stream successfully closed")

Kommentarer

Metoden Close rensar de resurser som används av en WebResponse och stänger den underliggande strömmen genom att anropa Stream.Close metoden.

Note

Svaret måste stängas för att undvika att systemresurserna börjar ta slut. Svarsströmmen kan stängas genom att anropa Stream.Close eller Close.

Note

Klassen WebResponse är en abstract klass. Det faktiska beteendet för WebResponse instanser vid körning bestäms av den underordnade klassen som returneras av WebRequest.GetResponse. Mer information om standardvärden och undantag finns i dokumentationen för de underordnade klasserna, till exempel HttpWebResponse och FileWebResponse.

Gäller för

Se även