Beispiel #1
0
        static public AttemptResult Attempt(AttemptProcess process, long milliseconds)
        {
            if (milliseconds > 0)
            {
                Timer timer = new Timer(milliseconds).StartAndGet();

                do
                {
                    AttemptResult result = process();
                    if (result.IsComplete())
                    {
                        return(result);
                    }

                    if (timer.GetTimeLeftInMilliseconds() > 50)
                    {
                        Thread.Sleep(1);
                    }
                }while (timer.IsTimeUnder());

                return(AttemptResult.Tried);
            }

            return(process());
        }