Ejemplo n.º 1
0
        public void RetryOnAnyTest1()
        {
            //no ex
            var @thisInt = 0;
            var times    = 2;
            var @this    = RetryHelper.RetryOnAny <int>(times: times, action: () =>
            {
                return(GetNotSupportedValues(false));
            }, (i, e) =>
            {
                @thisInt += i;
            });

            Assert.AreEqual(@this, 10086);
            Assert.AreEqual(@thisInt, 0);

            //ex
            @this    = 0;
            @thisInt = 0;
            @this    = RetryHelper.RetryOnAny <int>(times: times, action: () =>
            {
                return(GetNotSupportedValues(true));
            }, (i, e) =>
            {
                @thisInt += i;
            });
            Assert.AreEqual(@this, 0);
            //1 + 2 = 3
            Assert.AreEqual(@thisInt, 3);
        }
Ejemplo n.º 2
0
        private void button2_Click(object sender, EventArgs e)
        {
            this.FixedSingle();
            appSetting = (AppSetting)propertyGrid1.SelectedObject;
            appSetting.SaveSelf(appSetting);
            LogForm.Info(appSetting.ToJson());

            var c  = 0;
            var x5 = 0;

            for (int i = 1; i <= 10; i++)
            {
                c  += i * i;
                x5 += i * 5;
                LogForm.Successful($"**:{c}  +%=:{x5}");
            }

            var res = RetryHelper.RetryOnAny <string>(times: 0, () =>
            {
                return(SayHello());
            }, (i, ex) =>
            {
                MessageBox.Show($"出现异常_{i}_{ex.Message}");
            });

            MessageBox.Show(res);
        }
Ejemplo n.º 3
0
        public void RetryOnAnyTest()
        {
            var @this = RetryHelper.RetryOnAny <int>(times: 2, action: () =>
            {
                return(GetNotSupportedValues(false));
            });

            Assert.AreEqual(@this, 10086);

            //throw ,return defalut value ,int => 0
            var @this1 = RetryHelper.RetryOnAny <int>(times: 1, action: () =>
            {
                return(GetNotSupportedValues(true));
            });

            Assert.AreEqual(@this1, 0);
        }