[Quickfix-developers] Quick Fix - Initiator Not releasing resources on exception
Brought to you by:
orenmnero
From: Lloyd, R. <Rob...@st...> - 2008-12-17 09:27:10
|
Hi All, I am using the QuickFix engine in a C# windows service and building an Initiator that restarts following any exceptions. I am testing this by throwing exceptions within the Applications event handling methods. Currently if I do this I get the exception I expect first time through but then when I try and set up the Initiator again I get the following exception: Message = "Configuration failed: Could not open body file: C:\\PROJECTS_DOTNET\\QuickFix Service\\FixService\\files\\FIX.4.4-A-B.body" Now I know the file exists as it works the first time and if I try and open the file this is denied: The process cannot access the file because it is being used by another process. Which leads me to believe that something is not releasing the resources on this file. Is there a way I can manually free up the resources or would something need to be altered within the QuickFix libraries themselves? Or am I simply handling this in the wrong manner? I have attached the method that handles this process below. Thanks in advance Rob private void StartMorcomMonitor() { Initiator initiator = null; SessionSettings settings = null; FileStoreFactory storeFactory = null; Application application = null; ScreenLogFactory logFactory = null; MessageFactory messageFactory = null; try { String SettingsFilePath = ConfigurationManager.AppSettings["SettingsFilePath"]; settings = new SessionSettings(SettingsFilePath); application = new Application(); //main work handling class storeFactory = new FileStoreFactory(settings); logFactory = new ScreenLogFactory(true, true, true); messageFactory = new DefaultMessageFactory(); //create the Quickfix application initiator = new ThreadedSocketInitiator(application, storeFactory, settings, logFactory, messageFactory); initiator.start(); //if service state has changed inform it support if (m_ConnectionsUp == false) { m_ConnectionsUp = true; Informer.SendEmail("Morcom service is available again", false, true); } // Keep the Morcom monitor thread running until SCM issues a stop request. while (m_StopRequested == false) { Thread.Sleep(10000); //put this into the configuration file once complete } try { Informer.LogInformation("Morcom monitor thread stopping"); initiator.stop(); } catch (Exception e) { //catch any exception caused on closedown so no restart applied string errorMessage = string.Concat("Morcom Monitor caught exception on closedown", Environment.NewLine, e.GetType().FullName, Environment.NewLine, e.Message, Environment.NewLine, e.StackTrace); Informer.LogError(errorMessage); } } catch (Exception e) { if (initiator != null) { initiator.stop(); } application = null; settings = null; initiator = null; GC.Collect(); //log error string errorMessage = string.Concat("Morcom Monitor caught exception", Environment.NewLine, e.GetType().FullName, Environment.NewLine, e.Message, Environment.NewLine, e.StackTrace); Informer.LogError(errorMessage); //sleep for one minute and restart - also put into configuration file once complete Thread.Sleep(60000); StartMorcomMonitor(); } } ***************************************************************************** This communication is sent by the Standard Bank Plc or one of its affiliates The registered details of Standard Bank Plc are: Registered in England No. 2130447, Registered Office 25 Dowgate Hill London EC4R 2SB Authorised and Regulated by the Financial Services Authority. More information on Standard Bank is available at www.standardbank.com Everything in this email and any attachments relating to the official business of Standard Bank Group Limited and any or all subsidiaries, the Company, is proprietary to the Company. It is confidential, legally privileged and protected by relevant laws. The Company does not own and endorse any other content. Views and opinions are those of the sender unless clearly stated as being that of the Company. The person or persons addressed in this email are the sole authorised recipient. Please notify the sender immediately if it has unintentionally, or inadvertently reached you and do not read, disclose or use the content in any way and delete this e-mail from your system. The Company cannot ensure that the integrity of this email has beenmaintained nor that it is free of errors, virus, interception or interference. The sender therefore does not accept liability for any errors or omissions in the contents of this message which arise as a result of e-mail transmission. If verification is required please request a hard-copy version. This message is provided for informational purposes and should not be construed as a solicitation or offer to buy or sell any securities or related financial instruments. ***************************************************************************** |