Dưới đây là hàm trả về "true" or "false" để kiểm tra máy tính có kết nối với Internet hay không. Dưới đây mình sử dụng lớp "Ping" để kiểm tra kết nối tới "google" nếu Ping thành công sẽ trả về "true" ngược lại "false".
Code đơn giản thôi không phức tạp lắm :)
private bool IsConnectedToInternet()
{
try
{
Ping myPing = new Ping();
string host = "google.com";
byte[] buffer = new byte[32];
int timeout = 1000;
PingOptions pingOptions = new PingOptions();
PingReply reply = myPing.Send(host, timeout, buffer, pingOptions);
if (reply.Status == IPStatus.Success)
{
return true;
}
else return false;
}
catch
{
return false;
}
}
9/4/14
[C#] Kiểm tra máy tính có kết nối mạng với C#
Đến cuối cùng thứ mà con người theo đuổi chính là được sống một cuộc đời thật sự hạnh phúc
8/3/14
[IIS] Sửa lỗi web trên IIS ERROR 500.21
ERR0R500.21: Handler “PageHandlerFactory-Integrated” has a bad module “ManagedPipelineHandler” in its module list
Để sửa lỗi này các bạn làm theo cách sau:
Đầu tiên nhấn nút Start > gõ cmd
+ Nếu hệ điều hành là 64 bit tại cmd gõ lệnh này:
%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_regiis.exe -i
+ Nếu hệ điều hành là 32 bit tại cmd gõ lệnh này:
%windir%\Microsoft.NET\Framework\v4.0.21006\aspnet_regiis.exe -i
Đến cuối cùng thứ mà con người theo đuổi chính là được sống một cuộc đời thật sự hạnh phúc
4/4/14
[Regular Expression] Ultrapico Expresso v3.0.3276 - Công cụ hữu ích khi lập trình regular expression
Product Description:
Click để xem các bài đăng về quản trị mạng - thiết kế web
- Build complex regular expressions by selecting components from a palette
- Test expressions against real or sample input data
- Display all matches in a tree structure, showing captured groups, and all captures within a group
- Build replacement strings and test the match and replace functionality
- Highlight matched text in the input data
- Test automatically for syntax errors
- Generate Visual Basic or C# code
- Save and restore data in a project file
- Maintain and expand a library of frequently used regular expressions
Đến cuối cùng thứ mà con người theo đuổi chính là được sống một cuộc đời thật sự hạnh phúc
Subscribe to:
Posts (Atom)