IErrorList use in OrderSaving event handler

Discussions related to custom development with Select.
Post Reply
joe.mag
Posts: 122
Joined: Thu Aug 04, 2011 3:11 pm

IErrorList use in OrderSaving event handler

Post by joe.mag »

I'm trying to use the IErrorList interface to add errors encountered in my package's custom pre-save processing. If an error is generated and I make the calls to add the error I end up hanging Select. It just displays "Initializing Errors and Warnings" in the left corner of the status bar, shows an hour glass, and never comes back. I have to use Task Manager to kill the process. I don't see any errors added to the list prior to the hang.

Here's my code:

Code: Select all

        void OrderSavingHandler(object sender, EventArgs e)
        {

            IErrorList errorList2 = null;
            try
            {
                errorList2 = GetService<IErrorList>();
            }
            catch (Exception) { }

            errorList2.Add("this is a test", ErrorKind.Error, new Uri("http://www.microsoft.com"));
            // Note: commenting this next line out makes no difference -- still hangs.
            errorList2.Show();
            
            return;
        }
Note: calling the code from elsewhere (for instance, I call it from a ActiveDocumentChanged event handler) works fine.

I'd like to "play nice" but SoftPro won't share its toys.
Mark McKenna

Re: IErrorList use in OrderSaving event handler

Post by Mark McKenna »

It is likely that a cross-thread operation is occurring and causing your UI to hang. The saving of an order from the Order Editor pane occurs on a worker thread, which you are then tapping into with an event handler that attempts to update the Errors/Warnings tool window (a control which was originally created on the UI thread). Try using the IShell.Invoke method to marshal your code to execute on the correct thread.
Post Reply