2017-04-19 15 views
0

私は準備されたtopshelf.ThisプロジェクトとWindowsサービスを持っている要求XMLのデータを送信するXMLデータリストオブジェクトを直列化し、これらのオブジェクトはSQLからの情報を更新します。ときに約8メガバイト約1.8ギガバイトのメモリが範囲外の例外を増加した後にサービスを開始する。なぜ?TopShelf Windowsサービスのメモリリーク時にSQLからの情報を更新

public class HostService 
{ 

    private readonly Timer _updaterThread; 
    private readonly object _lockObject; 
    private readonly Manager _manager; 
    public HostService() 
    { 
     _manager = new Manager(); 
     _lockObject = new object(); 
     var interval = Convert.ToInt32(ConfigurationManager.AppSettings["UpdateInterval"]); 
     _updaterThread = new Timer(interval) { AutoReset = true }; 
     _updaterThread.Elapsed += UpdateInfo; 
    } 

    public void Start() 
    { 
     try 
     { 
      LoadLogger(); 
      _updaterThread.Start(); 

     } 
     catch (Exception e) 
     { 
      FXEventLogger.Instance().AddLog(EventLogEntryType.Error, e); 
     } 
    } 

    private void UpdateInfo(object state, EventArgs ev) 
    { 
     lock (_lockObject) 
     { 
      _manager.UpdateFmdProductions(); 
     } 
    } 



    public void Stop() 
    { 
     try 
     { 

      _updaterThread.Stop(); 
      FXEventLogger.Instance().AddLog(EventLogEntryType.SuccessAudit, "Service stopped"); 
      FXEventLogger.Finalize(); 
     } 
     catch (Exception e) 
     { 
      FXEventLogger.Instance().AddLog(EventLogEntryType.Error, e); 
     } 
    } 
+0

てください、ショー「UpdateFmdProductions (); " – KreminT

+0

UpdateFmdProductionsには、次の2つのメソッド呼び出しがあります。 –

答えて

0

** UpdateFmdProductions()2つのプロセスまずを作る** `パブリッククラスSmdStatusProvider {

public List<MakerInfo> GetMakersInfo() 
    { 
     SMDStatusServiceClient requester = null; 
     try 
     { 
      requester = new SMDStatusServiceClient(); 

      var response = requester.Request("//MachineStatus[@MachineType='MAKER']/ShiftStatus"); 

      return ParseMakersInfo(response); 
     } 
     catch (Exception e) 
     { 
      FXEventLogger.Instance().AddLog(EventLogEntryType.Error, e); 

      return null; 
     } 
     finally 
     { 
      requester.Close(); 
      GC.SuppressFinalize(this); 
     } 
    } 


    private List<MakerInfo> ParseMakersInfo(string shiftStatesXml) 
    { 
     using (var sr = new StringReader(shiftStatesXml)) 
     { 
      var serializer = new XmlSerializer(typeof(List<MakerInfo>), new XmlRootAttribute("result")); 

      var _makersInfo = (List<MakerInfo>) serializer.Deserialize(sr); 

      sr.Dispose(); 

      return _makersInfo; 
     } 
    } 
}` 

パブリッククラスFMDRepository:SqlServerClient {

public FMDRepository(string connectionString) 
    { 
     ConnectionString = connectionString; 
    } 

    public bool UpdateRealProductions(IEnumerable<MakerInfo> makersInfo) 
    { 
     if (makersInfo == null) return false; 

     OpenConnection(); 

     foreach (var makerInfo in makersInfo) 
     { 
      var success = ExecuteNonQuery(
        String.Format("UPDATE [Shooter] SET [RealProduction]={0}, [LastUpdate]='{1:yyyy-MM-dd HH:mm:ss}' WHERE [Machine]='{2}'", 
         Math.Round(makerInfo.RealProduction, 0), DateTime.Now, 
         makerInfo.Machine)); 
      if (success == -1) 
      { 
       CloseConnection(); 
       return false; 
      } 
     } 
     CloseConnection(); 
     return true; 
    } 
} 
関連する問題