Skip to content

Connectivity implementation not thread-safe on Windows, returning incorrect network status #9972

@breenbob

Description

@breenbob

Description

On the WinUI platform, any calls to Connectivity.Current only work from the first thread to access the property. Subsequent calls from any other thread will cause a silent thread access exception:
image

That will end in a value of Unknown being returned:
image

Doesn't matter which thread is first - main thread or background thread, it will always return correct value, and continue to return the correct value for that thread. But if you try to access it from a different thread, that is when this issue occurs.

Steps to Reproduce

I've linked to a sample repro below. Just run and click button 1 then button 2, or button 2 then button 1 to invert the outcome.

Main thread before bg thread:
xJ9MaGocEK

Bg thread before main thread:
TSWdWFLxeB

Link to public reproduction project repository

https://github.com/breenbob/MauiWindowsConnectivityIssue

Version with bug

6.0.400

Last version that worked well

Unknown/Other

Affected platforms

Windows

Affected platform versions

10.0.17763.0

Did you find any workaround?

If checks are always done on the same thread you won't see the issue, but that's not a feasible long term solution.

Relevant log output

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-essentialsEssentials: Device, Display, Connectivity, Secure Storage, Sensors, App Infofixed-in-7.0.0-rc.2.6866Look for this fix in 7.0.0-rc.2.6866!platform/windowst/bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions