Word status bar frozen

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

Word status bar frozen
 
Charles Mager


Guest


I've got a problem when our add-in runs in Word. I've not tested in other versions, but this definitely occurs in Word 2013. The end result is the status bar (where it normally says PAGE 1 of 2 2,032 WORDS) is either blank or doesn't update.

I accidentally stumbled upon what I think is the cause, which was inside a Telerik WPF grid control we use. This control aggregates property changed events into a dictionary. It then uses a timer to raise these every so often.

So, I set about replicating this in an add-in myself. I created an add-in and added an empty User Control with the following code and added it to a Custom Task Pane:


public partial class UserControlWithTimer : UserControl
{
    private System.Timers.Timer _timer;

    public UserControlWithTimer()
    {
        InitializeComponent();                        
    }

    protected override void OnLoad(EventArgs e)
    {
        base.OnLoad(e);

        if (_timer == null)
        {
            _timer = new System.Timers.Timer();
            _timer.Interval = 100;
            _timer.Elapsed += OnTick;
            _timer.Start();
        }
    }
        
    private void OnTick(object sender, ElapsedEventArgs e)
    {
        Action action = () => { };
        BeginInvoke(action);
    }
}


And hey presto - the status bar is frozen.

I get exactly the same behaviour with VSTO, so I'm not expecting miracles. But if anyone could shed any light on this and make any suggestions it'd be much appreciated.
Posted 30 Sep, 2015 09:38:04 Top
Andrei Smolin


Add-in Express team


Posts: 18793
Joined: 2006-05-11
Hello Charles,

Please show the code that uses this class.


Andrei Smolin
Add-in Express Team Leader
Posted 30 Sep, 2015 09:47:08 Top
Charles Mager


Guest


Hi Andrei

I just added a CTP via the designer and told it to use that control. I've got a couple of sample projects (ADX and VSTO) I can send over. Where should I send them?
Posted 30 Sep, 2015 09:53:23 Top
Andrei Smolin


Add-in Express team


Posts: 18793
Joined: 2006-05-11
Please send me the ADX project to the support email address; you can find it in {Add-in Express installation folder}\readme.txt. Please make sure your email contains a link to this topic.


Andrei Smolin
Add-in Express Team Leader
Posted 30 Sep, 2015 09:55:24 Top
Charles Mager


Guest


Hi Andrei

Sent an email. Thanks for the quick responses!
Posted 30 Sep, 2015 10:03:47 Top
Andrei Smolin


Add-in Express team


Posts: 18793
Joined: 2006-05-11
Charles,

Does the issue occur if you comment the code of the OnTick event handler out?


Andrei Smolin
Add-in Express Team Leader
Posted 30 Sep, 2015 10:12:05 Top
Charles Mager


Guest


Hi Andrei

No, it doesn't. It appears to be the invocation back onto the UI thread that causes Word to stop updating the status bar. The code inside Telerik's control is similar, but as it's WPF it uses Dispatcher.BeginInvoke instead. The end result is the same, though.

I'm not familiar enough with Word internals, COM and the interaction of managed code to make any sort of guess as to what's going on here. It happens that I can disable this 'feature' of Telerik's GridView, but sadly it doesn't totally resolve the issue which probably means there are more controls I'm using that do something similar. Ideally I'd rather get to the bottom of it rather than have to try and work around it like that (as there's a very big risk of regression later!).
Posted 30 Sep, 2015 10:18:15 Top
Charles Mager


Guest


Empirical evidence on my machine shows that increasing the interval to 300ms brings the Word Count back and increasing to 400ms brings the Page Count back too. It's as if there's some time-out in Word and the invocation resets it so it's never rendered.
Posted 30 Sep, 2015 10:45:36 Top
Andrei Smolin


Add-in Express team


Posts: 18793
Joined: 2006-05-11
Charles,

Use System.Windows.Forms.Timer instead. You need to access the Word object model and on the main thread only. This also applies to controls on a custom task pane because Word creates them on the main thread.


Andrei Smolin
Add-in Express Team Leader
Posted 01 Oct, 2015 05:36:44 Top
Charles Mager


Guest


Hi Andrei

Unfortunately what timer I use isn't in my control - these timers are within Telerik's WPF controls. The small sample code is merely to replicate the issue.
Posted 01 Oct, 2015 06:03:21 Top