Skip to content

Commit

Permalink
Ensure to free Access instance when closing main form
Browse files Browse the repository at this point in the history
  • Loading branch information
mnieto committed Oct 4, 2020
1 parent bc54270 commit 2180430
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 6 deletions.
12 changes: 7 additions & 5 deletions AccessIO/AccessApp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,12 @@ public virtual void CloseDatabase() {
/// Free the MS Access instance
/// </summary>
public void QuitApplication() {
Application.Quit();
if (Application != null) {
Application.Quit();
System.Runtime.InteropServices.Marshal.FinalReleaseComObject(Application);
Application = null;
}

}

/// <summary>
Expand Down Expand Up @@ -190,10 +195,7 @@ public void Dispose() {
protected virtual void Dispose(bool dispoing) {
if (!this.disposed) {
if (dispoing) {
if (Application != null) {
Application.Quit();
Application = null;
}
QuitApplication();
}
disposed = true;
}
Expand Down
1 change: 1 addition & 0 deletions AccessScrCtrl/MainFrm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions AccessScrCtrl/MainFrm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -202,5 +202,8 @@ private void workingCopyTextBox_Leave(object sender, EventArgs e) {

}

private void MainFrm_FormClosed(object sender, FormClosedEventArgs e) {
objectTree.Dispose();
}
}
}
2 changes: 1 addition & 1 deletion AccessScrCtrl/MainFrm.resx
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@
AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj00LjAuMC4w
LCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODkFAQAAACZTeXN0
ZW0uV2luZG93cy5Gb3Jtcy5JbWFnZUxpc3RTdHJlYW1lcgEAAAAERGF0YQcCAgAAAAkDAAAADwMAAABU
CAAAAk1TRnQBSQFMAgEBAgEAARwBAAEcAQABEAEAARABAAT/AQkBAAj/AUIBTQE2AQQGAAE2AQQCAAEo
CAAAAk1TRnQBSQFMAgEBAgEAASQBAAEkAQABEAEAARABAAT/AQkBAAj/AUIBTQE2AQQGAAE2AQQCAAEo
AwABQAMAARADAAEBAQABCAYAAQQYAAGAAgABgAMAAoABAAGAAwABgAEAAYABAAKAAgADwAEAAcAB3AHA
AQAB8AHKAaYBAAEzBQABMwEAATMBAAEzAQACMwIAAxYBAAMcAQADIgEAAykBAANVAQADTQEAA0IBAAM5
AQABgAF8Af8BAAJQAf8BAAGTAQAB1gEAAf8B7AHMAQABxgHWAe8BAAHWAucBAAGQAakBrQIAAf8BMwMA
Expand Down
5 changes: 5 additions & 0 deletions AccessScrCtrlUI/ObjectTree.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,14 @@ public string FileName {
/// </summary>
public ObjectTree() {
InitializeComponent();
Disposed += ObjectTree_Disposed;
tree.PathSeparator = System.IO.Path.DirectorySeparatorChar.ToString();
}

private void ObjectTree_Disposed(object sender, EventArgs e) {
App.QuitApplication();
}

/// <summary>
/// Constructor
/// </summary>
Expand Down

0 comments on commit 2180430

Please sign in to comment.