懒得勤快 3 سال پیش
والد
کامیت
7bae2377fe
2فایلهای تغییر یافته به همراه41 افزوده شده و 19 حذف شده
  1. 8 1
      src/Masuit.MyBlogs.Core/Views/Dashboard/Counter.razor
  2. 33 18
      src/Masuit.MyBlogs.Core/Views/Post/PostOnline.razor

+ 8 - 1
src/Masuit.MyBlogs.Core/Views/Dashboard/Counter.razor

@@ -4,6 +4,7 @@
 @using Masuit.MyBlogs.Core.Common
 @using Masuit.MyBlogs.Core.Common
 @using Masuit.Tools
 @using Masuit.Tools
 @using System.IO
 @using System.IO
+@using Masuit.Tools.Logging
 @inject IJSRuntime JS;
 @inject IJSRuntime JS;
 
 
 <h3 class="text-center">
 <h3 class="text-center">
@@ -140,7 +141,13 @@
     [JSInvokable]
     [JSInvokable]
     public static PerformanceCounter GetCurrentPerformanceCounter()
     public static PerformanceCounter GetCurrentPerformanceCounter()
     {
     {
-        return PerfCounter.GetCurrentPerformanceCounter();
+        try {
+            return PerfCounter.GetCurrentPerformanceCounter();
+        }
+        catch (Exception e) {
+            LogManager.Error(e);
+            return new PerformanceCounter();
+        }
     }
     }
 
 
     public void ClearMemory()
     public void ClearMemory()

+ 33 - 18
src/Masuit.MyBlogs.Core/Views/Post/PostOnline.razor

@@ -22,35 +22,50 @@
 
 
     protected override void OnInitialized()
     protected override void OnInitialized()
     {
     {
-        var key = nameof(PostOnline) + ":" + Id;
-        online = CacheManager.AddOrUpdate(key, new HashSet<string>(), set =>
-        {
-            set.Add(IP);
-            return set;
-        }, 3).Count;
-        CacheManager.Expire(key, ExpirationMode.Sliding, TimeSpan.FromMinutes(5));
-        _timer = new Timer(_ =>
-        {
-            online = CacheManager.Get(key)?.Count ?? 0;
-            InvokeAsync(StateHasChanged);
-        }, null, 0, 1000);
+        try {
+            var key = nameof(PostOnline) + ":" + Id;
+            online = CacheManager.AddOrUpdate(key, new HashSet<string>(), set =>
+            {
+                set.Add(IP);
+                return set;
+            }, 3).Count;
+            CacheManager.Expire(key, ExpirationMode.Sliding, TimeSpan.FromMinutes(5));
+            _timer = new Timer(_ =>
+            {
+                online = CacheManager.Get(key)?.Count ?? 0;
+                InvokeAsync(StateHasChanged);
+            }, null, 0, 1000);
+        }
+        catch {
+            // ignored
+        }
     }
     }
 
 
     public void ShowViewer()
     public void ShowViewer()
     {
     {
         if (online > 0 && IsAdmin)
         if (online > 0 && IsAdmin)
         {
         {
-            JS.InvokeVoidAsync("showViewer", CacheManager.Get(nameof(PostOnline) + ":" + Id).Select(s => KeyValuePair.Create(s, s.GetIPLocation().ToString())));
+            try {
+                JS.InvokeVoidAsync("showViewer", CacheManager.Get(nameof(PostOnline) + ":" + Id).Select(s => KeyValuePair.Create(s, s.GetIPLocation().ToString())));
+            }
+            catch {
+                // ignored
+            }
         }
         }
     }
     }
 
 
     public ValueTask DisposeAsync()
     public ValueTask DisposeAsync()
     {
     {
-        online = CacheManager.AddOrUpdate(nameof(PostOnline) + ":" + Id, new HashSet<string>(), set =>
-        {
-            set.Remove(IP);
-            return set;
-        }).Count;
+        try {
+            online = CacheManager.AddOrUpdate(nameof(PostOnline) + ":" + Id, new HashSet<string>(), set =>
+            {
+                set.Remove(IP);
+                return set;
+            }).Count;
+        }
+        catch {
+            // ignored
+        }
         return _timer?.DisposeAsync() ?? ValueTask.CompletedTask;
         return _timer?.DisposeAsync() ?? ValueTask.CompletedTask;
     }
     }
 }
 }