From f09ed9efcf7ff93237f3824ef2b979fa459756f0 Mon Sep 17 00:00:00 2001 From: h-hg <1394564544@qq.com> Date: Mon, 31 Jul 2023 13:58:02 +0800 Subject: [PATCH] fix: error in C# --- csharp/core/Common.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/csharp/core/Common.cs b/csharp/core/Common.cs index 7646f1e9..04b9d168 100644 --- a/csharp/core/Common.cs +++ b/csharp/core/Common.cs @@ -24,13 +24,14 @@ namespace AlibabaCloud.TeaUtil public static class Common { private static readonly string _defaultUserAgent; - private static readonly _processStartTime; + private static readonly long _processStartTime; private static long _seqId = 0; static Common() { _defaultUserAgent = GetDefaultUserAgent(); - _processStartTime = Process.GetCurrentProcess().StartTime; + long ticks = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).Ticks; + _processStartTime = (long)((double)ticks / TimeSpan.TicksPerSecond); } public static byte[] ToBytes(string val) @@ -136,7 +137,7 @@ public static string GetNonce() long currentTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(); long seq = Interlocked.Increment(ref seqId); long randNum = new Random().NextInt64(); - string msg = $"{process_start_time}-{thread_id}-{current_time}-{seq}-{randNum}"; + string msg = string.Format("{0}-{1}-{2}-{3}", _processStartTime, threadId, currentTime, seq, randNum); using (MD5 md5 = MD5.Create()) { byte[] hash = md5.ComputeHash(System.Text.Encoding.UTF8.GetBytes(msg));