Event for Closing VSTO on an Inspector

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

Event for Closing VSTO on an Inspector
Catch Event when Form Closing 
Darrin Edwards


Guest


Hi Guys, first post here I think.

I have created an outlook VSTO using Addin Express for Outlook Regions.

I am trying to catch an event when the region closes and prior to being destroyed, so I can delete some files and paths attached to a temp directory ...

At the moment the following code is used:


        private void ImagePreviewRegion_FormClosing(object sender, FormClosingEventArgs e)
        {
            // delete our files
            int index = 0;
            for (int i = 0; i < _Files.Length; i++)
            {
                try
                {
                    // delete the file
                    File.Delete(_Files[i]);
                }
                catch (Exception)
                {
                    Debug.WriteLine("Delete Dir " + _path + " failed");
                    // silent fail
                }
                finally
                {
                    //
                }

            }//for
            try
            {   // delete temp directory
                if (System.IO.Directory.Exists(_path))
                {
                    System.IO.Directory.Delete(_path);
                }
            }
            catch (Exception)
            {
                Debug.WriteLine("Delete Dir " + _path + " failed");
                // silent fail
            }
            finally
            {
                //
            }

        }


As you can see i place that code in the ImagePreviewRegion_FormClosing(object sender, FormClosingEventArgs e) (where ImagePreviewRegion is a replacement region.

What steps to I take to ensure that this even fires when the inspector closes, so I can clean up my mess?

MTIA

Darrin
Posted 30 Aug, 2018 06:31:42 Top
Andrei Smolin


Add-in Express team


Posts: 18829
Joined: 2006-05-11
Hello Darrin,

Darrin Edwards writes:
I am trying to catch an event when the region closes and prior to being destroyed


Depending on the context, Add-in Express may hide the region and destroy (or show it again) later.

You can use:
1) the ADXOlForm.AfterFormHide event;
2) override the standard OnHandleDestroyed() method: protected override void OnHandleDestroyed(EventArgs e);
3) the Isnpector.Close() event.


Andrei Smolin
Add-in Express Team Leader
Posted 30 Aug, 2018 07:33:12 Top
Darrin Edwards


Guest


Hi Andrei

Thanks for the reply ... is there any reason why the FormClosing event is not firing?

I have overridden the OnHandleDestroyed method for the moment and that works fine ... but would like to understand the FormClosing event ...

MTIA

DWE
Posted 30 Aug, 2018 13:56:36 Top
Andrei Smolin


Add-in Express team


Posts: 18829
Joined: 2006-05-11
Hello Darrin,

The event isn't fired because the form isn't closed; Add-in Express hides it, not closes. To generalize it, Add-in Express controls the creation and destruction of the form.


Andrei Smolin
Add-in Express Team Leader
Posted 31 Aug, 2018 01:51:38 Top