Click here to Skip to main content
15,890,845 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i am trying to work with wifi networks. for that i am using WiFiAdapter but i cannot create it's instance as it says that this doesnot have construtor of x parameters. then i tried to scan networks and store it in wifinetworkreport but it's giving the same problem.

What I have tried:

WiFiNetworkReport networkReport; ;
networkReport = wiFiAdapter.NetworkReport;
IReadOnlyList<WiFiAvailableNetwork> readOnlyList = new List<WiFiAvailableNetwork>();
readOnlyList = networkReport.AvailableNetworks;



but this is giving Null pointer. so how can get the networks fro this class or create an instance of the classes that dont have constructors. dont they have default constructors?
Posted
Updated 21-Jan-19 22:12pm
Comments
[no name] 21-Jan-19 17:39pm    
You need to show more code ... like what you've been doing with / to (local) "wifiAdapter".

1 solution

Yes, u can't create an instance of this class.
You need to use, for example, the following:

C#
WiFiAdapter wiFiAdapter = WiFiAdapter.FindAllAdaptersAsync().GetResults().First();

- Get all WiFi-Adapter of the system
- Get the first one which is a instance of a WiFiAdapter

Or you could use this approach to iterate through each adapter and perform a specific action:
C#
private async void WiFiAdapterSample()
        {
            var systemsWiFiAdapter = await WiFiAdapter.FindAllAdaptersAsync();
            foreach (var wifiAdapter in systemsWiFiAdapter)
            {
                // do something
            }
        }
 
Share this answer
 
v2
Comments
Member 13541763 28-Jan-19 0:32am    
this code is generating error msg of that it(returning type) doesnot contain definition for 'getawaiter' etc.
Member 13541763 28-Jan-19 0:34am    
i have done it by a bad way but however that's working. my code is

var list = WiFiAdapter.FindAllAdaptersAsync();
Thread.Sleep(timeout);

it's working fine so far although it's not a good way
Daniel Wosch 28-Jan-19 2:54am    
Sure.
As async method is used u need to use the await keyword as posted in the second code example working with the foreach loop.
Your code using Thread.Sleep is bad style to achive this.
LiQuick 13-Jan-22 19:04pm    
When i do "var adapters = await WiFiAdapter.FindAllAdaptersAsync();" multiple times I get the following error: "An attempt was made to establish a session to a network server, but there are already too many sessions established to that server. (Exception from HRESULT: 0x800704C4)". Any idea how i can avoid this error? I need to scan multiple times (making a wifi heatmapper application).

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900