src/Shared/EntityFramework/Migrations/Utilities/UtcNowGenerator.cs
// <summary>
// Returns the value of <see cref="DateTime.UtcNow" /> unless this value would be the same as the
// last value returned by this thread calling this method, in which case the thread pushes the value
// a little bit into the future. The comparison is in terms of the form used to store migration ID
// in the database--i.e. to the 1/10 second.
// </summary>
// <remarks>
// There should never be any pushing to the future involved for normal use of migrations, but when
// this method is called in rapid succession while testing or otherwise calling the DbMigrator APIs
// there may be occasional sleeping.
// </remarks>
Returns the value of  unless this value would be the same as the
last value returned by this thread calling this method, in which case the thread pushes the value
a little bit into the future. The comparison is in terms of the form used to store migration ID
in the database--i.e. to the 1/10 second.
Returns the value of unless this value would be the same as the last value returned by this thread calling this method in which case the thread pushes the value a little bit into the future . The comparison is in terms of the form used to store migration ID in the database -- i . e . to the 1 / 10 second .
[Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Globalization", "CA1305:SpecifyIFormatProvider", MessageId = "System.DateTime.ToString(System.String)", Justification = "It only objects to the statement in Debug.Assert() which is only for debug mode.")]
        public static DateTime UtcNow()
        {
            var now = DateTime.UtcNow;
            var lastNow = _lastNow.Value;
            if (now <= lastNow
                || now.ToString(MigrationIdFormat, CultureInfo.InvariantCulture)
                      .Equals(lastNow.ToString(MigrationIdFormat, CultureInfo.InvariantCulture), StringComparison.Ordinal))
            {
                now = lastNow.AddMilliseconds(100);
                Debug.Assert(!now.ToString(MigrationIdFormat).Equals(lastNow.ToString(MigrationIdFormat), StringComparison.Ordinal));
            }
            _lastNow.Value = now;
            return now;
        }
[ Diagnostics . CodeAnalysis . SuppressMessage ( " " , " " , MessageId = " " , Justification = " " ) ] public static DateTime UtcNow ( ) { var now = DateTime . UtcNow ; var lastNow = _lastNow . Value ; if ( now <= lastNow || now . ToString ( MigrationIdFormat , CultureInfo . InvariantCulture ) . Equals ( lastNow . ToString ( MigrationIdFormat , CultureInfo . InvariantCulture ) , StringComparison . Ordinal ) ) { now = lastNow . AddMilliseconds ( 100 ) ; Debug . Assert ( ! now . ToString ( MigrationIdFormat ) . Equals ( lastNow . ToString ( MigrationIdFormat ) , StringComparison . Ordinal ) ) ; } _lastNow . Value = now ; return now ; }
Returns the value of  unless this value would be the same as the
last value returned by this thread calling this method, in which case the thread pushes the value
a little bit into the future.
Returns the value of unless this value would be the same as the last value returned by this thread calling this method in which case the thread pushes the value a little bit into the future .
// At least on some machines DateTime.UtcNow can return values that are a little bit (< 1 second) less than the // last value that it returned.
remarks
There should never be any pushing to the future involved for normal use of migrations, but when
this method is called in rapid succession while testing or otherwise calling the DbMigrator APIs
there may be occasional sleeping.
There should never be any pushing to the future involved for normal use of migrations but when this method is called in rapid succession while testing or otherwise calling the DbMigrator APIs there may be occasional sleeping .