Pages: 1
Print
Author Topic: Close xmetal with multiple documents open  (Read 2435 times)
Qing
Member

Posts: 12


« on: December 13, 2013, 03:45:19 AM »

Hi all,
I met a problem with closing xmetal application (I am working with xmetal authoring essential 7.0).
If I just open one document, then close the xmetal, the run sequence of macros is: On_Document_Close and On_Applciation_Close. It's fine to me.
However, when there are multiple documents opened, and I click the close button, On_Document_Activate macro will run first.

I can understand this somehow, but my problem is that, On_Document_Activate in my customization will trigger the code to call web service to do query and then refresh the tool bar according to the result. When call web service and close xmetal happen together, the code refreshing tool bar which runs on UI thread will prevent it from ending which further hangs the xmetal process. That means that the xmetal ui close but not destroy and the process is still on.

I an wondering if there is anything I can do to check the current behavior is closing xmetal and then not trigger the macro the On_Document_Active?

Many Thanks.
Logged
Qing
Member

Posts: 12


« Reply #1 on: December 15, 2013, 07:47:31 PM »

Any one there? There question is so weird or I didn't make it clear?
Logged
Derek Read
Program Manager (XMetaL)
Administrator
Member

Posts: 2621



WWW
« Reply #2 on: December 16, 2013, 04:37:03 PM »

I believe the general answer is that you need to make sure to release all COM objects you have instantiated and not rely on garbage collection to do that. Seems you understand this already and are just trying to figure out your own logic to do that. Tough one.

It sounds to me like you made some assumptions about when they need to be released and that you will need to change your logic so they can be released sooner. If they are being instantiated at a global variable level then you might have more flexibility on when you can release them. Just make sure that your release code always runs. If they are instantiated at the local level then you will want to release them as soon as they are no longer needed. That might mean they are instantiated and then released more often than in your original design.

One more thing: Be careful when modifying toolbars. Toolbar buttons should only be added or removed in the events named "On_Default_CommandBars_Complete" (for app-level/all-dtd changes) and "On_CommandBars_Load_Complete" (for dtd-specific commandbars). Direct toolbar modifications during other event macros are not supported. You can modify whether a macro is enabled or pushed in, which in turn affects whether a toolbar button (and or menu item) is greyed out or pushed in. You do this using DisableMacro() and PushInMacro() inside the On_Update_UI event. Don't try to make direct changes to the buttons themselves that mimic this behaviour.
Logged
Qing
Member

Posts: 12


« Reply #3 on: December 16, 2013, 07:55:12 PM »

Thanks for reply Derek.
It is really tough to figure out the right time and way to release all the com objects, and the web service interaction makes it even more tough.
So I just want to simplify it to see if there is any way to disable the document change macro when close the xmetal with multiple docs open. Is there any way to achieve this?
And I find a most simple way is the API Application.Quit(1) at the end of On_Application_Close macro and after the necessary release work.But, does this method secure?
Logged
Pages: 1
Print
Jump to:  

email us