Jelajahi Sumber

1. Fix 平行處理Counter issue ,改成 Interlocked.Increment

Jessica Tseng 2 tahun lalu
induk
melakukan
ed83973305

+ 2 - 2
EVCB_OCPP.TaskScheduler/App.config

@@ -10,8 +10,8 @@
     <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.1" />
   </startup>
   <connectionStrings>
-    <add name="OnlineLogDBContext" connectionString="data source=172.1.2.187\SQLEXPRESS2017;initial catalog=StandardOCPP_OnlineRecord;;persist security info=True;user id=sa;password=Ph0930118811;MultipleActiveResultSets=True;App=EntityFramework" providerName="System.Data.SqlClient" />
-    <add name="MainDBContext" connectionString="data source=172.1.2.187\SQLEXPRESS2017;initial catalog=StandardOCPP_Main;;persist security info=True;user id=sa;password=Ph0930118811;MultipleActiveResultSets=True;App=EntityFramework" providerName="System.Data.SqlClient" />
+    <add name="OnlineLogDBContext" connectionString="data source=172.1.2.187;initial catalog=StandardOCPP_OnlineRecord;;persist security info=True;user id=sa;password=Ph0930118811;MultipleActiveResultSets=True;App=EntityFramework" providerName="System.Data.SqlClient" />
+    <add name="MainDBContext" connectionString="data source=172.1.2.187;initial catalog=StandardOCPP_Main;;persist security info=True;user id=sa;password=Ph0930118811;MultipleActiveResultSets=True;App=EntityFramework" providerName="System.Data.SqlClient" />
   </connectionStrings>
 
 <!--<common>

+ 11 - 11
EVCB_OCPP.TaskScheduler/Services/CommonCustomerService.cs

@@ -138,7 +138,7 @@ namespace EVCB_OCPP.TaskScheduler.Services
                                     ErrorMsg = response.Success ? null :
                                     (response.Exception == null ? response.Response : response.Exception.ToString())
                                 });
-                                completecounter++;
+                                Interlocked.Increment(ref completecounter);
                             }
 
                         });
@@ -156,8 +156,8 @@ namespace EVCB_OCPP.TaskScheduler.Services
                 {
                     logger.Error("Assigned_StartTransactionCallbackTask Exception: " + ex.GetBaseException().ToString());
                 }
-
-                ChargeRecordCallCounter++;
+                Interlocked.Increment(ref ChargeRecordCallCounter);
+            
             }, TaskCreationOptions.AttachedToParent);
 
 
@@ -229,9 +229,8 @@ namespace EVCB_OCPP.TaskScheduler.Services
 
                             if (!string.IsNullOrEmpty(r.Fee) && string.IsNullOrEmpty(r.Receipt))
                             {
-                                //如果有計費但還沒結算 不回報給客戶
-                                completecounter++;
-
+                                //如果有計費但還沒結算 不回報給客戶                              
+                                Interlocked.Increment(ref completecounter);
                             }
                             else
                             {
@@ -270,7 +269,8 @@ namespace EVCB_OCPP.TaskScheduler.Services
                                         ErrorMsg = response.Success ? null :
                                         (response.Exception == null ? response.Response : response.Exception.ToString())
                                     });
-                                    completecounter++;
+                                    Interlocked.Increment(ref completecounter);
+                                   
                                 }
                             }
 
@@ -298,7 +298,7 @@ namespace EVCB_OCPP.TaskScheduler.Services
                     logger.Error("Assigned_StartTransactionCallbackTask Exception: " + ex.GetBaseException().ToString());
                 }
 
-                ChargeRecordCallCounter++;
+                Interlocked.Increment(ref ChargeRecordCallCounter);
             }, TaskCreationOptions.AttachedToParent);
 
 
@@ -398,8 +398,8 @@ namespace EVCB_OCPP.TaskScheduler.Services
                                     ReportedOn = DateTime.Now,
                                     ErrorMsg = response.Success ? null :
                                     (response.Exception == null ? response.Response : response.Exception.ToString())
-                                });
-                                completecounter++;
+                                });                              
+                                Interlocked.Increment(ref completecounter);
                             }
 
                         });
@@ -424,7 +424,7 @@ namespace EVCB_OCPP.TaskScheduler.Services
                     logger.Debug("Assigned_ReportExecutionofRemoteCommandTask Exception: " + ex.GetBaseException().ToString());
                 }
 
-                ChargeRecordCallCounter++;
+                Interlocked.Increment(ref ChargeRecordCallCounter);
             }, TaskCreationOptions.AttachedToParent);