How can I avoid the failure to find a server interface in webbrowser?

Source: Internet
Author: User

You have used the webbrowser control. Haha. It can provide us with a lot of convenient operations.
However, if the computer cannot access the Internet or the network speed is slow, it will not be a great deal if there is an interface that cannot find the server. Haha. At least I think so.

What should we do? Check the network connection.

If (! Start. checkconnect ())
{
This. axwebbrowser1.navigate ("about: <style> frame, HTML, body {margin: 0px; padding: 0px ;} </style> <br> <Div style = 'color: red; font-size: 20px; font-weight: bolder; text-align: center; 'valign = 'center'> You must connect to the Internet to use this function. </Div> <br> <center> <a href = 'wy: // refresh (); 'style = 'text-align: center; font-size: 12px; color: Blue; cursor: hand; '> retry </a> </center> ", ref arg2, ref arg2, ref arg3, ref arg4 );
Return;
}

Checkconnect is a function that checks whether it is connected to the Internet. Its core function is to use the system. net. DNS. Resolve static class for detection.

Public static bool checkconnect ()
{
Bool B = true;
Try
{
Iphostentry IPS = system. net. DNS. Resolve ("www.5inet.net ");
B = true;
}
Catch (exception ex)
{
B = false;
Console. writeline (ex. tostring ());
}
Return B;
}

If the check fails, navigate webbrowser to about: add your error message to the end. It's easy.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.