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 theWin32_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 calledINetCfgLock
you could use to acquire an exclusive lock for changing network adapter settings. To acquire the lock use theINetCfgLock::AcquireWriteLock
method.BEGIN EDIT:
Here is a link to the project on codeproject which shows the use of the
INetCfgLock
COM interface and theINetCfgLock::AcquireWriteLock
in C#.END EDIT
Hope, this helps.