Tell me more ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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?

share|improve this question

2 Answers

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.

share|improve this answer
 
Cannot figure out how to use it. I catch Invalid cross-thread access. when create instance of DispatcherTimer –  Feusp Sep 13 at 13:05
 
Try using a normaler timer then, the dispatcher timer is tied to the dispatcher thread (UI-Thread) –  floAr Sep 16 at 6:20

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.