Quantcast
Channel: Visual C# forum
Viewing all articles
Browse latest Browse all 31927

PROBLEM DISABLING/ENABLING THE NETWORK ADAPTER WHEN RRAS IS ENABLED

$
0
0
hello all, I am using the following code to disable/enable the lan card:

SelectQuery wmiQuery = new SelectQuery("SELECT * FROM Win32_NetworkAdapter WHERE NetConnectionId != NULL");
                    ManagementObjectSearcher searchProcedure = new ManagementObjectSearcher(wmiQuery);
                    foreach (ManagementObject item in searchProcedure.Get())
                    {
                        if (((string)item["NetConnectionId"]) == interfaceName)
                        {
                            switch (newState)
                            {
                                case 0:
                                    item.InvokeMethod("Disable", null);
                                    richTextBox1.Invoke((Action)(() => { richTextBox1.AppendText("\nAdapter was disabled"); }));
                                    break;
                                case 1:
                                    item.InvokeMethod("Enable", null);
                                    richTextBox1.Invoke((Action)(() => { richTextBox1.AppendText("\nAdapter was enabled\n"); }));
                                    Thread.Sleep(2000);
                                    netmon();
                                    break;
                            }
                        }
                    }

and this code is running fine, but whenever I am enabling the RRAS (Routing and Remote Access) from services.msc or via registry or via process in c#, disabling and enabling the adapter takes a long long time...how to solve the problem?

Viewing all articles
Browse latest Browse all 31927

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>