IncrementWithAction() 공개 메소드

public IncrementWithAction ( long expectedCount, System.Action act ) : bool
expectedCount long
act System.Action
리턴 bool
예제 #1
0
        protected override void ReadModifyWriteState(Action <SmartSyncState> act)
        {
            int retries         = 5;
            int sleepIntervalMs = 1000;

            for (; ;)
            {
                var current = _counter.GetCurrent();
                var success = _counter.IncrementWithAction(current, () =>
                {
                    var state = ReadState();
                    act(state);
                    var nextStateFile = _stateFile.FullName + ".next";
                    using (var fs = new FileStream(nextStateFile, FileMode.Create, FileAccess.Write))
                    {
                        SmartSyncState.WriteToStream(fs, state);
                    }
                    File.Replace(nextStateFile, _stateFile.FullName, null, true);
                });
                if (success)
                {
                    return;
                }
                else
                {
                    if (retries < 0)
                    {
                        throw new System.IO.IOException("Unable to update after several retries.");
                    }
                    System.Threading.Thread.Sleep(sleepIntervalMs);
                    sleepIntervalMs *= 2;
                    retries--;
                }
            }
        }