连接到 Wifi 或 Lan 时调用 C# 函数
我已经知道如何检查是否有互联网连接。 但我希望当用户插入 LAN 线路或连接到 WiFi 网络时调用此(函数)。基本上是为我的大学创建自动登录。
I already know how to check if there's a connection to the internet.
But I want this(function) to be called when the user plugs a lan line in or connect to a wifi network. Basically am creating a Auto-Login for my university.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
NetworkInterfaceType.Lan 适用于 LAN
NetworkInterfaceType.Lan works for LAN
到目前为止,最简单的方法是简单地尝试定期运行标准自动登录过程,如果它工作正常,则用户已登录,如果不工作,则说明没有连接。除非您正在编写某种网络连接诊断应用程序,否则尝试确定为什么没有连接是没有意义的。
By far the easiest method is to simply attempt to periodically run the standard auto login procedure, if it works all is well and the user is logged in if it does not then there is no connection. There is little point trying to determine WHY there is no connection unless you are writitng some kind network connectivity diagnostic app.
我想你可以有一个侦听器线程,它将简单地检查互联网连接的状态,并在连接出现或丢失时引发事件。
I suppose you can have a listener thread which will simply check status of internet connection and raise event if connection appeared or lost.