protected void InternalDispose(bool disposing) { // If you need thread safety, use a lock around these // operations, as well as in your methods that use the resource. if (!_disposed) { if (disposing) { if (Victor != null) { try { Victor.StopServer(); System.Runtime.InteropServices.Marshal.ReleaseComObject(InstrumentServ); Thread.Sleep(1000);//give it time to close System.Runtime.InteropServices.Marshal.ReleaseComObject(Victor); } catch { } } if (ProtocolTree != null) { try { Marshal.ReleaseComObject(ProtocolTree); } catch { } } if (m_Assay != null) { try { Marshal.ReleaseComObject(m_Assay); } catch { } } Victor = null; ProtocolTree = null; m_Assay = null; InstrumentServ = null; GC.Collect();//call disposers GC.Collect();//finalize _disposed = true; } } }
public void StartVictor() { //EVERYTHING HERE IS CRITICAL!!!!!!! //this code is very difficult to work with because the Victor server is so damn out of date //there is an automatic wrapper class the VS generated, and these AxInterops should be used //YOU MUST ADD THE VICTOR TO THE CONTROL OF THE THING!!! THIS IS VITAL System.Resources.ResourceManager resources = new ResourceManager(typeof(VictorForm)); this.Victor = new AxMlrCtls.AxVictor(); ((System.ComponentModel.ISupportInitialize)Victor).BeginInit(); Victor.OcxState = (System.Windows.Forms.AxHost.State)resources.GetObject("Victor.OcxState"); this.Victor.Location = new System.Drawing.Point(388, 172); this.Victor.Name = "Victor"; this.Victor.Size=new System.Drawing.Size(18,17); Victor.PerformLayout(); Victor.OcxState = (System.Windows.Forms.AxHost.State)resources.GetObject("Victor.OcxState"); this.Controls.Add(Victor); //Victor.CreateControl();-this appears to work just as well ((System.ComponentModel.ISupportInitialize)this.Victor).EndInit(); this.PerformLayout(); Victor.StartServer(0); Victor.ResultEventsEnabled=true; Victor.PlateEventsEnabled=true; Victor.StateEventsEnabled=true; Victor.AssayEventsEnabled=true; Victor.StateEventsEnabled=true; Victor.ServerState +=new EventHandler(Victor_ServerState); Victor.ServerAssayEnd+=new _DVictorEvents_ServerAssayEndEventHandler(Victor_ServerAssayEnd); Victor.ServerPlateUnload += new _DVictorEvents_ServerPlateUnloadEventHandler(Victor_ServerPlateUnload); }