Microsoft.Protocols.TestTools.StackSdk.CommonStack.HttpClientTransport.Dispose C# (CSharp) Method

Dispose() protected method

Release resources.
protected Dispose ( bool disposing ) : void
disposing bool /// If disposing equals true, managed and unmanaged resources are disposed. /// If false, only unmanaged resources can be disposed. ///
return void
        protected virtual void Dispose(bool disposing)
        {
            if (!this.disposed)
            {
                // If disposing equals true, dispose all managed and unmanaged resources.
                if (disposing)
                {
                    // Free managed resources & other reference types:
                    if (this.httpWebRequest != null)
                    {
                        this.httpWebRequest.KeepAlive = false;
                        this.httpWebRequest = null;
                    }

                    if (this.httpWebResponse != null)
                    {
                        this.httpWebResponse.Close();
                        this.httpWebResponse = null;
                    }
                }
            }

            // Call the appropriate methods to clean up unmanaged resources.
            // If disposing is false, only the following code is executed:
            this.disposed = true;
        }

Same methods

HttpClientTransport::Dispose ( ) : void

Usage Example

        protected bool SetupHttpsConnection()
        {
            sutControlAdapter.ClearCache(testConfig.HostedCacheServerComputerFQDNOrNetBiosName);

            int timeout = 20000;
            byte[] content = TestUtility.GenerateRandomArray(10);

            HttpClientTransport testClient = new HttpClientTransport(
                TransferProtocol.HTTPS,
                testConfig.HostedCacheServerComputerName,
                testConfig.HostedCacheServerHTTPSListenPort,
                PchcConsts.HttpsUrl,
                testConfig.DomainName,
                testConfig.UserName,
                testConfig.UserPassword);
            try
            {
                testClient.Send(HttpVersion.Version10, null, content, HttpMethod.POST, timeout);
            }
            catch (Exception)
            {
                return false;
            }
            finally
            {
                testClient.Dispose();
            }

            return true;
        }