修改网络适配器属性时如何保证独占访问 [英] How to guarantee exclusive access when modifying network adapter properties

查看:112
本文介绍了修改网络适配器属性时如何保证独占访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用WMI的Win32_NetworkAdapterConfiguration类EnableStatic方法来设置回送网络适配器的静态IP进行测试。我注意到,在可见的属性表中,操作系统已将其锁定。当用户关闭更改后的工作表时,事情会冻结直到更新完成。



如何确保C#程序和Windows UI之间的互斥访问?

解决方案

我认为 Win32_NetworkAdapterConfiguration <的 EnableStatic 方法类已经获取了排他锁,以更改网络适配器设置。微软的知识库文章使我得出以下结论: Microsoft KB
还有一个名为 INetCfgLock 的COM接口,您可以使用它来获取用于更改网络适配器设置的排他锁。要获取锁,请使用 INetCfgLock :: AcquireWriteLock 方法。



开始编辑:



这是 codeproject上的项目链接,其中显示了在C#中使用 INetCfgLock COM接口和 INetCfgLock :: AcquireWriteLock 的情况。 p>

结束编辑



希望如此,这很有帮助。


I am using WMI's Win32_NetworkAdapterConfiguration class, EnableStatic method to set static IPs of a Loopback network adapter for testing. I noticed that the OS takes out a lock when there's a visible property sheet. When user dismisses the sheet with changes, things freeze up until the update has completed.

How can I ensure exclusive access between my program in C# and Windows UI?

解决方案

I think the EnableStatic method of the Win32_NetworkAdapterConfiguration class already acquires an exclusive lock to change the network adapter settings. A microsoft knowledge base article lead me to this conclusion Microsoft KB. There is also a COM interface called INetCfgLock you could use to acquire an exclusive lock for changing network adapter settings. To acquire the lock use the INetCfgLock::AcquireWriteLock method.

BEGIN EDIT:

Here is a link to the project on codeproject which shows the use of the INetCfgLock COM interface and the INetCfgLock::AcquireWriteLock in C#.

END EDIT

Hope, this helps.

这篇关于修改网络适配器属性时如何保证独占访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆