Пример #1
0
        public void GetResultsOnCallback(IAsyncResult ar)
        {
            GetAddressDelegate del = (GetAddressDelegate)
                                     ((AsyncResult)ar).AsyncDelegate;

            try
            {
                string result;
                result = del.EndInvoke(ar);
                Console.WriteLine("\nOn CallBack: result is " + result);
            }
            catch (Exception ex)
            {
                Console.WriteLine("\nOn CallBack, problem occurred: " + ex.Message);
            }
        }
Пример #2
0
        public void GetAddressAsyncWait(string name)
        {
            GetAddressDelegate dc = new GetAddressDelegate(this.GetAddress);

            IAsyncResult ar = dc.BeginInvoke(name, null, null);

            // Main thread can in principle do other work now
            try
            {
                string result = dc.EndInvoke(ar);
                Console.WriteLine("\nAsync waiting : " + result);
            }
            catch (Exception ex)
            {
                Console.WriteLine("\nAsync waiting, a problem occurred : " +
                                  ex.Message);
            }
        }
Пример #3
0
        public void GetResultsOnCallback(IAsyncResult ar)
        {
            GetAddressDelegate del = (GetAddressDelegate)((AsyncResult)ar).AsyncDelegate;

            try
            {
                string result;
                result = del.EndInvoke(ar);
                lock (this)
                {
                    this.address = result;
                    this.status  = ResultStatus.Done;
                }
            }
            catch (Exception ex)
            {
                lock (this)
                {
                    this.address = ex.Message;
                    this.status  = ResultStatus.Failed;
                }
            }
        }