c#异常后重试操作

 private void TryConnect(System.Action action)

        {
            int retries = 3;
            while(true)
            {
                try
                {
                    action();
                    break; //success!
                }
                catch
                {
                    if (--retries == 0)
                    {
                      //........
                        break; 
                    }
                    else Thread.Sleep(1000);
                }
            }
        }
posted @ 2018-03-06 17:12  程序猿kid  阅读(272)  评论(0编辑  收藏  举报