FtpClient.BeginDisconnect Method

System.Net.FtpClient

Collapse image Expand Image Copy image CopyHover image
Initiates a disconnection on the server

Namespace: System.Net.FtpClient
Assembly: System.Net.FtpClient (in System.Net.FtpClient.dll) Version: 1.0.5064.17461

Syntax

C#
public IAsyncResult BeginDisconnect(
	AsyncCallback callback,
	Object state
)
Visual Basic
Public Function BeginDisconnect ( 
	callback As AsyncCallback,
	state As Object
) As IAsyncResult
Visual C++
public:
virtual IAsyncResult^ BeginDisconnect(
	AsyncCallback^ callback, 
	Object^ state
) sealed

Parameters

callback
Type: System..::..AsyncCallback
AsyncCallback method
state
Type: System..::..Object
State object

Return Value

Type: IAsyncResult
IAsyncResult

Implements

IFtpClient..::..BeginDisconnect(AsyncCallback, Object)

Examples

C#  Copy imageCopy
using System;
using System.Net;
using System.Net.FtpClient;
using System.Threading;

namespace Examples {
    public static class BeginDisconnectExample {
        static ManualResetEvent m_reset = new ManualResetEvent(false);

        public static void BeginDisconnect() {
            using (FtpClient conn = new FtpClient()) {
                m_reset.Reset();

                conn.Host = "localhost";
                conn.Credentials = new NetworkCredential("ftptest", "ftptest");
                conn.Connect();
                conn.BeginDisconnect(new AsyncCallback(BeginDisconnectCallback), conn);

                m_reset.WaitOne();
            }
        }

        static void BeginDisconnectCallback(IAsyncResult ar) {
            FtpClient conn = ar.AsyncState as FtpClient;

            try {
                if (conn == null)
                    throw new InvalidOperationException("The FtpControlConnection object is null!");

                conn.EndDisconnect(ar);
            }
            catch (Exception ex) {
                Console.WriteLine(ex.ToString());
            }
            finally {
                m_reset.Set();
            }
        }
    }
}

See Also