Exemplo n.º 1
0
        public void CreateWxaQrCodeAsyncTest()
        {
            var dt1      = DateTime.Now;
            var filePath = "../../Config/qr-async.jpg";

            Task.Factory.StartNew(async() =>
            {
                var ms     = new MemoryStream();
                var result = await WxAppApi.CreateWxQrCodeAsync(base._appId, ms, "pages/websocket", 100);
                Assert.AreEqual(ReturnCode.请求成功, result.errcode);

                ms.Seek(0, SeekOrigin.Begin);
                //储存图片
                File.Delete(filePath);
                using (var fs = new FileStream(filePath, FileMode.CreateNew))
                {
                    await ms.CopyToAsync(fs);
                    await fs.FlushAsync();
                }

                Assert.IsTrue(File.Exists(filePath));
            });
            var dt2 = DateTime.Now;

            while (!File.Exists(filePath))
            {
            }
            var dt3 = DateTime.Now;

            Console.WriteLine("执行时间:{0}ms", (dt2 - dt1).TotalMilliseconds);
            Console.WriteLine("等待时间:{0}ms", (dt3 - dt2).TotalMilliseconds);
        }
Exemplo n.º 2
0
        public void CreateWxaQrCodeAsyncTest2()
        {
            var dt1      = DateTime.Now;
            var filePath = "../../Config/qr-async2.jpg";

            Task.Factory.StartNew(async() =>
            {
                var result = await WxAppApi.CreateWxQrCodeAsync(base._appId, filePath, "pages/websocket", 100);
                Assert.AreEqual(ReturnCode.请求成功, result.errcode);
                Assert.IsTrue(File.Exists(filePath));
            });
            var dt2 = DateTime.Now;

            while (!File.Exists(filePath))
            {
            }
            var dt3 = DateTime.Now;

            Console.WriteLine("执行时间:{0}ms", (dt2 - dt1).TotalMilliseconds);
            Console.WriteLine("等待时间:{0}ms", (dt3 - dt2).TotalMilliseconds);
        }