Detect Windows (IE) proxy settings changes

2019-04-12 09:16发布

问题:

I'm using WinHttpGetIEProxyConfigForCurrentUser and friends to gather the current proxy information when my app starts as doing it before each request seems to degrade performance greatly with it something sitting for a few seconds gathering the proxy data. Is there a way to detect when the Windows proxy settings have changed so I can cache the information until it changes?

Thanks, J

回答1:

Not sure if there is a better way, but you could always take the nuclear option and use RegNotifyChangeKeyValue with HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings.



回答2:

Could you run the detection in a background thread upon application startup?

I found nothing about WinHttpGetIEProxyConfigForCurrentUser not being callable from within the non-main-UI thread.

If the application needs the result of the WinHttpGetIEProxyConfigForCurrentUser faster than the background thread returns, you could make it blocking again until the background thread is finished.



回答3:

I'm not sure if it is generated with proxy setting changes or not, but there might be a WM_SETTINGCHANGE message that you could handle.