System.Threading.Tasks并发和异步代码使用

main.cs 

System.Threading.Tasks.Parallel.For(0, 10, i =>
            {
                TestLock testLock = RedisBillLockWrapper.Wrap<TestLock>(new TestLock());

                testLock.Run();
            });
            Console.Read();

testlock.cs

 class TestLock : MarshalByRefObject
    {
        [RedisBillLock("127.0.0.1", "memcache_lock_service_key_test")]
        public void Run()
        {
            Console.WriteLine("{0:yyyyMMddHHmmssfff}获取了锁", DateTime.Now);
            Thread.Sleep(1000);
        }
    }

 

 

 

posted @ 2013-12-02 11:35  快乐就好  阅读(843)  评论(0编辑  收藏  举报