1
\$\begingroup\$

Since there is no timeout for responce in windows phone xna version of WebClient i need to implement one. The idea is to make MyWebClient derived class from WebClient with timer. But i got stuck on it. Is there any way to implement timer here without using Update for every instance of MyWebClient so that i can use it like WebClient?

\$\endgroup\$

2 Answers 2

0
\$\begingroup\$

What about using a DispatcherTimer ? You could start the timer with your timeout a Interval value and register a tick event. When the event fires you throw a exception for a timeout (or do whatever pleases you). You could even hook up the DownloadProgressChanged event of the webclient and reset the timer or smth. like this.

\$\endgroup\$
2
  • \$\begingroup\$ Cannot figure out how to use it. I catch Invalid cross-thread access. when create instance of DispatcherTimer \$\endgroup\$
    – Feusp
    Commented Sep 13, 2013 at 13:05
  • \$\begingroup\$ Try using a normaler timer then, the dispatcher timer is tied to the dispatcher thread (UI-Thread) \$\endgroup\$
    – floAr
    Commented Sep 16, 2013 at 6:20
0
\$\begingroup\$

Problem solved by using static varible TotalGameTime in main game Update

protected override void Update(GameTime gameTime)
        {
            TotalGameTime += gameTime.ElapsedGameTime.TotalSeconds;
        }

And then in MyWebClient save start state of TotalGameTime and compare with current gameTime

while (currentGameTime - startGameTime < timeout)
                    {
                       //
                    currentGameTime = Game1.TotalGameTime;                            
                    }

I dont find this solution clean but anyway it solves the problem.

\$\endgroup\$

Not the answer you're looking for? Browse other questions tagged .