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
EnableStaticmethod of theWin32_NetworkAdapterConfigurationclass 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
INetCfgLockyou could use to acquire an exclusive lock for changing network adapter settings. To acquire the lock use theINetCfgLock::AcquireWriteLockmethod.BEGIN EDIT:
Here is a link to the project on codeproject which shows the use of the
INetCfgLockCOM interface and theINetCfgLock::AcquireWriteLockin C#.END EDIT
Hope, this helps.