Environment.SetEnvironmentVariable(
environmentVariable,
value,
“Machine”
);
但是,在单个测试系统(运行XP和Windows 7)上,这个单个调用需要2秒多的时间.
I figured out,这可能是因为:“如果目标是User或Machine,则通过Windows WM_SETTINGCHANGE消息通知其他应用程序设置操作.”
有没有办法将此通知抑制到其他应用程序,以便我的环境快速设置并返回..?
请注意,我有一个组件可以设置大约20个环境变量,如果我使用上面描述的功能,则需要大约一分钟才能完成该任务.
请建议!!
解决方法
If this parameter is HWND_BROADCAST
((HWND)0xffff),the message is sent to
all top-level windows in the system,
including disabled or invisible
unowned windows. The function does not
return until each window has timed
out. Therefore,the total wait time
can be up to the value of uTimeout
multiplied by the number of top-level
windows.
但fuFlags参数设置为0.
SMTO_NORMAL (0x0000): The calling
thread is not prevented from
processing other requests while
waiting for the function to return.SMTO_BLOCK (0x0001): Prevents the
calling thread from processing any
other requests until the function
returns.