Ticket Q236990
Visible to All Users

refreshing data from a timer event

created 15 years ago

Hello, how is it possible to refresh data in timer event in a ViewController without getting the "Cross-thread operation not valid" message
This is my timer event in the viewcontroller
        void EvRefreshTimer_Elapsed(object sender, ElapsedEventArgs e)
        {
              View.ObjectSpace.Refresh();
              //Frame.GetController<DevExpress.ExpressApp.SystemModule.RefreshController>().RefreshAction.DoExecute();
        }

Show previous comments (2)
Anatol (DevExpress) 15 years ago

    Hello Trond,
    Thank you for your sample. Unfortunately, today we've been a little bit overloaded with support queries.
    We are working on your issue, and will answer you ASAP.
    Thanks,
    Anatol

    Anatol (DevExpress) 15 years ago

      Hello Trond,
      I apologize for the delay in responding. To solve the problem, you should update the GridControl's datasource in the same thread, in which the GridControl is created. To do it, use the Control.Invoke method, as shown in the following code:

      C#
      void fRefreshTimer_Elapsed(object sender, ElapsedEventArgs e) { ((Control)Frame.Template).Invoke(new ThreadStart(delegate() { ((DevExpress.ExpressApp.ListView)View).CollectionSource.Reload(); })); }

      Please let me know if you need any further help.
      Thanks,
      Anatol

        Perfect !
        Thanks.

        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.