How to detect the connection status of the network (C #)

xiaoxiao2021-03-19  179

1. The method defined in [DllImport ( "wininet.dll")] private extern static bool InternetGetConnectedState (out int connectionDescription, int reservedValue); 2. Description Parameter Method: connectionDescription: connection Description reservedValue: retention Return Value: true: On Line false : OFF line 3. Call method a. You must reference system.Runtime.InteropServices in your code, otherwise there will be compilation error b. Define a variable INT i = 0; c. Call Bool State = InternetGetConnectedState (Out i, 0); the complete code: using System.Runtime.InteropServices; namespace internet {public class Class1 {[DllImport ( "wininet.dll")] private extern static bool InternetGetConnectedState (out int connectionDescription, int reservedValue); public Class1 () { } private bool isconnected () {INT i = 0; Bool State = InternetGetConnectedState (OUT I, 0); Return State;}}}}

转载请注明原文地址:https://www.9cbs.com/read-130233.html

New Post(0)