Ejemplo n.º 1
0
        /// <summary>
        /// Initiates an asynchronous transfer.
        /// </summary>
        /// <param name="callback">The delegate to be called when the operation completes (or <c>null</c>).</param>
        /// <param name="state">Application defined state (or <c>null</c>).</param>
        /// <returns>The <see cref="IAsyncResult" /> to be used to track the operation.</returns>
        /// <remarks>
        /// <note>
        /// For server sessions, passing <paramref name="callback" /> as <c>null</c> indicates
        /// that the session will automatically call <see cref="EndTransfer" /> when the operation completes.
        /// Applications that wish to track the transfer completion must pass a non-<c>null</c> callback.
        /// </note>
        /// </remarks>
        public IAsyncResult BeginTransfer(AsyncCallback callback, object state)
        {
            if (started)
            {
                throw new InvalidOperationException("Cannot reuse a StreamTransferSession instance.");
            }

            started = true;

            if (reliableSession.IsClient)
            {
                return(reliableSession.BeginTransfer(serverEP, direction, Helper.NewGuid(), 0, args, null, null));
            }

            // Server side transfers start automatically when the message
            // handler returns.

            arTransfer = new AsyncResult(null, callback, state);

            arTransfer.Started();
            return(arTransfer);
        }