Ticket T247596
Visible to All Users

Determening if a ViewControllers View or Frame or what it is called is visible

created 10 years ago

Is there any way of determening if a specific listview is visible?

We have a timer which regurarly refreshes a listview, but if another view is in focus the refresh lags the current window. Therefore I would like to write in the ViewController for the list view:

In the OnActivated method of the ListView ViewController we start the timer:
 protected override void OnActivated()
        {
            fOppfriskTimer = new System.Timers.Timer();
            fOppfriskTimer.Interval = 5 * 60 * 1000; // hvert 5te minutt
            fOppfriskTimer.Elapsed += new ElapsedEventHandler(EvTimerOppfrisk);
            fOppfriskTimer.Start();

base.OnActivated();
        }

In the EvTimerOppfrisk event handler we do this:
        private void EvTimerOppfrisk(object sender, ElapsedEventArgs e)
        {
            try
            {
               // It's here I would like to check if the ListView is in front and only run the reload if so
                ((Control)Frame.Template).Invoke(new ThreadStart(() => ((DevExpress.ExpressApp.ListView)View).CollectionSource.Reload()));
            }
            catch
            {
                // Ignorer feil
            }
        }

If I run the reload without the  ((Control)Frame.Template).Invoke(new ThreadStart(() … part I get the following message:
Cross thread operation detected. To suppress this exception, set DevExpress.Data.CurrencyDataController.DisableThreadingProblemsDetection = true

I'm not sure of the consequences of setting the DisableThreadingProblemsDetection to true.

Suggestions?

Terje

Answers approved by DevExpress Support

created 10 years ago

Hello Terje,

In general, your approach is correct and the Invoke operation is required since the System.Timers.Timer.Elapsed event occurs in the different thread.
It is likely you can resolve the lag problem by un-handling the Timer.Elapsed event in the overridden ViewController.OnDeactivate method.
Please review the attached sample and check if it meets your needs.

    Comments (3)

      Will this approach work in an MDI application?

        OnDeactivate does not run unless you close the listview so that approach won't work I think.

        DevExpress Support Team 10 years ago

          Hello Terje,

          It is a standard approach to subscribe to the events of different objects in the overridden ViewController.OnActivated method (or event handler) and unsubscribe from them in the overridden OnDeactivate method (or event handler). In the case of Tabbed MDI interface, you can use the approach shown in the Catch ViewChanged event in MDI Tabbed application ViewController thread to catch the moment when an active View is changed to stop the timers. We look forward to your reply once you've had the opportunity to implement our suggestion.

          Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

          Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.