FtpWebRequest.BeginGetRequestStream(AsyncCallback, Object) Yöntem

Tanım

Bir isteğin içerik akışını yazmak üzere zaman uyumsuz olarak açmaya başlar.

public:
 override IAsyncResult ^ BeginGetRequestStream(AsyncCallback ^ callback, System::Object ^ state);
public override IAsyncResult BeginGetRequestStream(AsyncCallback? callback, object? state);
public override IAsyncResult BeginGetRequestStream(AsyncCallback callback, object state);
override this.BeginGetRequestStream : AsyncCallback * obj -> IAsyncResult
Public Overrides Function BeginGetRequestStream (callback As AsyncCallback, state As Object) As IAsyncResult

Parametreler

callback
AsyncCallback

AsyncCallback İşlem tamamlandığında çağırma yöntemine başvuran bir temsilci.

state
Object

İşlem hakkında bilgi içeren kullanıcı tanımlı bir nesne. İşlem tamamlandığında bu nesne temsilciye callback geçirilir.

Döndürülenler

IAsyncResult İşlemin durumunu gösteren örnek.

Özel durumlar

Bu yönteme yapılan önceki bir çağrı veya GetRequestStream() henüz tamamlanmamış.

FTP sunucusuna bağlantı kurulamadı.

Method özelliği olarak UploadFileayarlanmadı.

Örnekler

Aşağıdaki kod örneği, bir isteğin akışını almak için zaman uyumsuz bir işlemin başlamasını gösterir. Bu kod örneği, sınıfa genel bakış için FtpWebRequest sağlanan daha büyük bir örneğin parçasıdır.

// Command line arguments are two strings:
// 1. The url that is the name of the file being uploaded to the server.
// 2. The name of the file on the local machine.
//
public static void Main(string[] args)
{
    // Create a Uri instance with the specified URI string.
    // If the URI is not correctly formed, the Uri constructor
    // will throw an exception.
    ManualResetEvent waitObject;

    Uri target = new Uri (args[0]);
    string fileName = args[1];
    FtpState state = new FtpState();
    FtpWebRequest request = (FtpWebRequest)WebRequest.Create(target);
    request.Method = WebRequestMethods.Ftp.UploadFile;

    // This example uses anonymous logon.
    // The request is anonymous by default; the credential does not have to be specified.
    // The example specifies the credential only to
    // control how actions are logged on the server.

    request.Credentials = new NetworkCredential ("anonymous","janeDoe@contoso.com");

    // Store the request in the object that we pass into the
    // asynchronous operations.
    state.Request = request;
    state.FileName = fileName;

    // Get the event to wait on.
    waitObject = state.OperationComplete;

    // Asynchronously get the stream for the file contents.
    request.BeginGetRequestStream(
        new AsyncCallback (EndGetStreamCallback),
        state
    );

    // Block the current thread until all operations are complete.
    waitObject.WaitOne();

    // The operations either completed or threw an exception.
    if (state.OperationException != null)
    {
        throw state.OperationException;
    }
    else
    {
        Console.WriteLine("The operation completed - {0}", state.StatusDescription);
    }
}

Açıklamalar

yöntemini çağırarak EndGetRequestStream zaman uyumsuz işlemi tamamlamanız gerekir. Genellikle tarafından EndGetRequestStream başvurulan yöntem tarafından callbackçağrılır. İşlemin durumunu belirlemek için bu yöntem tarafından döndürülen nesnedeki IAsyncResult özellikleri denetleyin.

Bu yöntem akışı beklerken engellemez. Engellemek için bu yöntemin yerine çağırın GetRequestStream .

Zaman uyumsuz programlama modelini kullanma hakkında ayrıntılı bilgi için bkz. Zaman Uyumlu Yöntemleri Zaman Uyumsuz Olarak Çağırma.

Note

Bu üye, uygulamanızda ağ izlemeyi etkinleştirdiğinizde izleme bilgilerini döndürür. Daha fazla bilgi için bkz. .NET Framework Ağ İzleme.

Arayanlara Notlar

Bu yöntem ağ trafiği oluşturur.

Şunlara uygulanır

Ayrıca bkz.