Timer in Browser form - InfoPath Dev
in

InfoPath Dev

Timer in Browser form

Last post 01-14-2008 11:47 AM by davidair. 2 replies.
Page 1 of 1 (3 items)
Sort Posts: Previous Next
  • 01-09-2008 01:43 PM

    Timer in Browser form

    I assume this is not possible but want to make sure before I give up:

    I want to automatically submit a form every five minutes while it's open in the browser. I do this to maintain a "lock" on the form, which is actually rendered as a secondary data source in another form.

    I was hoping to use System.Timers, but I can't access the MainDataSource. Below is the code I'm trying to use, calling it from a button:

     public void btnOpenIntro_Clicked(object sender, ClickedEventArgs e) {
                Timer aTimer = new Timer(10000);
                aTimer.Elapsed += new ElapsedEventHandler(OnTimedEvent);
                aTimer.Interval = 2000;
                aTimer.Enabled = true;

            }

    public void OnTimedEvent(object source, ElapsedEventArgs e) {
                XPathNavigator xpxp = MainDataSource.CreateNavigator();
            }


    When the code reaches the last line in OnTimedEvent, it returns an UnhandledOperationException: "Operation is not valid due to the current state of the object."

    Any suggestions? I'm pretty new to C#.
     

    Filed under: ,
  • 01-14-2008 07:49 AM In reply to

    Hi anotherchrisberry,

    At least the timer function is working correctly!  I'm not too familiar with IP07 OM code, but why do you need a reference to the Main DOM?  I would think that you need to call the Submit() method on one of your data source connection objects.

    Matt Faus / Microsoft InfoPath MVP
    Qdabra® Software / Streamline data gathering to turn process into knowledge
  • 01-14-2008 11:47 AM In reply to

    Hey Chris,

    Forms Server business logic runs only on the server during the postback. So if a postback was not initiated by the user you cannot really do anything. Consider this:

    - A user clicks a button
    - The form is submitted to the server and your code runs
    - Your code sets a timer, then FormsServer finishes rendering the form and sends it back to the client

    - Some time later, your timer fires... by this time the window where you were allowed to modify the data source has long ago gone because for the Formsserver persective it is done servicing the request and you have no more business modifying anything.

    So this approach would not work. What you can do instead is to host your form in a custom ASPX page and have some Javascript code to cause periodic postbacks of the entire page. This has a significant drawback though - it will result in weird user experience and potential data loss (imagine you're typing some text and suddenly the page does a postback and you've lost what you have typed... what if it was a large rich-text field?)

    If your locking mechanism is external to the form you can use AJAX to maintain the lock without refreshing the entire page, you might need to write a separate web service for that.

    Dave.

    David Airapetyan / Software Services Architect
    Qdabra® Software / Streamline data gathering to turn process into knowledge
Page 1 of 1 (3 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.