Main Site Documentation

HttpResponse freeze


#1

So i have set up a little project with a card reader and while the server is online it runs smooth. However once the server goes offline HttpResponse freezes and cant get out. i tought getting a reply code would help this but im all out of ideas.

Code as follows.

void Send2()
        {
            WebClient.GetFromWeb("http://" + IP + ":" + nPort + "/pool/user?ID=" + Card).ResponseReceived += 
                new HttpRequest.ResponseHandler(Program_ResponseReceived);
        }
        void Program_ResponseReceived(HttpRequest sender, HttpResponse response)
        {
            if (response.StatusCode == "200")
            {
                answer = response.Text;

                string[] nCard = answer.Split('/');

                name.Text = nCard[0].Trim('\\', '"');

                if (count == 0)
                {
                    on.Text = "Signed: On";
                    count++;
                }
                else
                {
                    on.Text = "Signed: Off";
                    count = 0;
                }

                time.Text = nCard[1].Trim('"');

                Glide.MainWindow = logonW;
            }
            else
            {
                name.Text = "Http-Response: " + response.StatusCode;
                Glide.MainWindow = logonW;
            }

            multicolorLed.BlinkOnce(GT.Color.Yellow);
            Thread.Sleep(500);
            multicolorLed.TurnGreen();
            welcome.Text = "Welcome";
            draw.Text = "Swipe card!";
            Glide.MainWindow = mainW;

        }

#2

@ Fajdo - There is an issue in NETMF where connecting to a remote endpoint never times out, so if the server isn’t there the code will never return. The solution some users use is to wrap the code that gets stuck in a thread and periodically abort it if needed.


#3

Ah, ok thanks! I’ll have to do that then… thanks for the reply.