コード例 #1
0
        public IAsyncResult BeginGetProduct(string id, AsyncCallback asyncCallBack, object asyncState)
        {
            Guid gId = Guid.Parse(id);

            ProductAsyncResult asyncResult = new ProductAsyncResult();

            asyncResult.AsyncState = asyncState;

            Action asyncProductMaker = () =>
            {
                Product p = new Product()
                {
                    ProductId = gId,
                    Sku       = "MyTestSku",
                    CreatedOn = DateTime.Now,
                    TimeStamp = gId.ToByteArray()
                };

                var goTo = DateTime.Now.AddMilliseconds(300);
                var time = DateTime.Now;
                while (time < goTo)
                {
                    time = DateTime.Now;
                }

                asyncResult.Data        = p;
                asyncResult.IsCompleted = true;
                asyncCallBack(asyncResult);
            };

            //Kick the method off asynchronously
            asyncProductMaker.BeginInvoke(null, null);
            return(asyncResult);
        }
コード例 #2
0
        public IAsyncResult BeginGetProduct(string id, AsyncCallback asyncCallBack, object asyncState)
        {
            Guid gId = Guid.Parse(id);

            ProductAsyncResult asyncResult = new ProductAsyncResult();
            asyncResult.AsyncState = asyncState;

            Action asyncProductMaker = () =>
            {
                Product p = new Product()
                {
                    ProductId = gId,
                    Sku = "MyTestSku",
                    CreatedOn = DateTime.Now,
                    TimeStamp = gId.ToByteArray()
                };

                var goTo = DateTime.Now.AddMilliseconds(300);
                var time = DateTime.Now;
                while (time < goTo)
                {
                    time = DateTime.Now;
                }

                asyncResult.Data = p;
                asyncResult.IsCompleted = true;
                asyncCallBack(asyncResult);
            };

            //Kick the method off asynchronously
            asyncProductMaker.BeginInvoke(null, null);
            return asyncResult;
        }
コード例 #3
0
        public Product EndGetProduct(IAsyncResult result)
        {
            ProductAsyncResult pResult = (ProductAsyncResult)result;

            return(pResult.Data);
        }
コード例 #4
0
        public Models.Product EndGetProductById(IAsyncResult result)
        {
            ProductAsyncResult pResult = (ProductAsyncResult)result;

            return(pResult.Data);
        }