Exemple #1
0
        /// <summary>Completes the specified asynchronous receive operation.</summary>
        /// <param name="asyncResult"></param>
        /// <returns></returns>
        public string EndLog(IAsyncResult asyncResult)
        {
            // Retrieve the delegate.
            LogItemCallback caller = (LogItemCallback)asyncResult.AsyncState;

            // Call EndInvoke to retrieve the results.
            string msg = (string)caller.EndInvoke(asyncResult);

            return(msg);
        }
Exemple #2
0
        /// <summary>
        /// Begin write to cache logger async.
        /// </summary>
        /// <param name="state"></param>
        /// <param name="callback"></param>
        /// <param name="level"></param>
        /// <param name="text"></param>
        /// <returns></returns>
        public IAsyncResult BeginLog(object state, AsyncCallback callback, LoggerLevel level, string text)
        {
            LogItemCallback caller = new LogItemCallback(LogItemWorker);

            if (callback == null)
            {
                callback = CreateCallBack();
            }

            // Initiate the asychronous call.  Include an AsyncCallback
            // delegate representing the callback method, and the data
            // needed to call EndInvoke.
            IAsyncResult result = caller.BeginInvoke(level, text, callback, caller);

            this.resetEvent.Set();
            return(result);
        }
Exemple #3
0
        /// <summary>
        /// AsyncLog
        /// </summary>
        /// <returns></returns>
        internal void LogAsync(LoggerLevel level, string text)
        {
            LogItemCallback caller = new LogItemCallback(LogItemWorker);

            // Initiate the asychronous call.
            IAsyncResult result = caller.BeginInvoke(level, text, CreateCallBack(), caller);

            result.AsyncWaitHandle.WaitOne();

            //while (!result.IsCompleted)
            //{
            //    Thread.Sleep(10);
            //}
            // Call EndInvoke to wait for the asynchronous call to complete,
            // and to retrieve the results.
            caller.EndInvoke(result);
        }