Access hangs on exit

Add-in Express™ Support Service
That's what is more important than anything else

Access hangs on exit
 
nektrasa




Posts: 28
Joined: 2015-05-07
Hi, I'm having some trouble with my Word/Excel/PowerPoint/Access add-in. For all the other applications it works fine, but when used with Access, Access hangs on exit.
Some of my code creates new a thread and does some synchronization with a Control, to make everything run in the GUI thread. I tried disabling the initialization code, but nothing changed.

Any idea what might be causing this?
Posted 11 Jun, 2015 12:30:48 Top
Andrei Smolin


Add-in Express team


Posts: 14140
Joined: 2006-05-11
Hello,

Turn all other COM add-ins off. Make sure there's no MSACCESS.EXE hanging in processes before you start Access.

I would start with an empty (no code) add-in. Then you can add a really simple code fragment to check if it produces the issue; if positive, check to make sure that your code accesses the Access object model as well as DAO and ADO on the main thread only and every COM object that your code creates is released.

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 12 Jun, 2015 04:24:58 Top
nektrasa




Posts: 28
Joined: 2015-05-07
Hi, Andrei. Thanks for your reply.

I had tried creating a simple add-in, but couldn't reproduce the problem. Your reminder regarding releasing COM objects helped me find the problem. I can reproduce it if I try to use AccessApp.CurrentProject. Do I need to do anything special with this object?
Posted 12 Jun, 2015 15:16:53 Top
Andrei Smolin


Add-in Express team


Posts: 14140
Joined: 2006-05-11
I would suggest retrieving and storing all required information that that object provides and releasing the object after doing this.

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 15 Jun, 2015 02:59:31 Top
nektrasa




Posts: 28
Joined: 2015-05-07
Right, but how do I release the object?
Posted 15 Jun, 2015 08:10:12 Top
Andrei Smolin


Add-in Express team


Posts: 14140
Joined: 2006-05-11
private void adxRibbonButton1_OnClick(object sender, IRibbonControl control, bool pressed) {
    Access._CurrentProject project = AccessApp.CurrentProject;
    string projectName = project.FullName;
    Marshal.ReleaseComObject(project); project = null;
    MessageBox.Show(projectName);
}


Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 15 Jun, 2015 08:42:16 Top
nektrasa




Posts: 28
Joined: 2015-05-07
Yes, that seems to have done the trick. Thanks!
Posted 15 Jun, 2015 10:35:04 Top
Andrei Smolin


Add-in Express team


Posts: 14140
Joined: 2006-05-11
Welcome!

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 16 Jun, 2015 02:42:12 Top