> ## Documentation Index
> Fetch the complete documentation index at: https://devdocs.xbox.com/llms.txt
> Use this file to discover all available pages before exploring further.

# XNetworkingUnregisterPreferredLocalUdpMultiplayerPortChanged

> XNetworkingUnregisterPreferredLocalUdpMultiplayerPortChanged

# XNetworkingUnregisterPreferredLocalUdpMultiplayerPortChanged

Unregisters a callback function that was registered with [XNetworkingRegisterPreferredLocalUdpMultiplayerPortChanged](/reference/networking/xnetworking/functions/xnetworkingregisterpreferredlocaludpmultiplayerportchanged).

## Syntax

```cpp theme={null}
bool XNetworkingUnregisterPreferredLocalUdpMultiplayerPortChanged(
         XTaskQueueRegistrationToken token,
         bool wait
)
```

### Parameters

*token*   \_In\_\
Type: [XTaskQueueRegistrationToken](/reference/system/xtaskqueue/structs/xtaskqueueregistrationtoken)

The token returned from [XNetworkingRegisterPreferredLocalUdpMultiplayerPortChanged](/reference/networking/xnetworking/functions/xnetworkingregisterpreferredlocaludpmultiplayerportchanged).

*wait*   \_In\_\
Type: bool

Indicates whether to block until any pending callbacks are completed.

### Return value

Type: bool

Returns false if *wait* is false and the unregister call is pending. Returns true otherwise.

## Remarks

<Note>This function is safe to call on a time-sensitive thread only if the *wait* parameter is false. For more information, see [Time-sensitive threads](https://learn.microsoft.com/gaming/gdk/docs/gdk-dev/console-dev/overviews/threads/time-sensitive-threads).</Note>

This function performs the following actions:

* The callback associated with the token is removed from the set of registered callbacks.
* If no callbacks are executing for that callback token, the call returns true.
* If callbacks are executing and *wait* is true, the call blocks until the executing callback has finished.
* If callbacks are executing and *wait* is false, the call does not block but does return false. When the callback for the token is complete, the token is automatically unregistered.

<Note>This function should not be called from within an [XNetworkingPreferredLocalUdpMultiplayerPortChangedCallback](/reference/networking/xnetworking/functions/xnetworkingpreferredlocaludpmultiplayerportchangedcallback) if *wait* is true since this will deadlock.</Note>

This mechanism allows for the following coding patterns:

* You can block on unregistration to ensure your callbacks are never invoked after an unregister call.
* You can choose not to block. If you need to ensure your callbacks are completed before deleting data, you can periodically call this function with *wait* set to false. When it finally returns true, all your callbacks are completed and you can delete the state.
* If your callback doesn't care whether it is being invoked during an unregister call, you can pass false for *wait* and ignore the return value.

## Requirements

**Header:** XNetworking.h

**Library:** xgameruntime.lib

**Supported platforms:** Windows, XBOX One family consoles and XBOX Series consoles

## Conceptual documentation

* [Time-sensitive threads](https://learn.microsoft.com/gaming/gdk/docs/gdk-dev/console-dev/overviews/threads/time-sensitive-threads)

## See also

[XNetworkingQueryPreferredLocalUdpMultiplayerPort](/reference/networking/xnetworking/functions/xnetworkingquerypreferredlocaludpmultiplayerport)\
[Preferred local UDP multiplayer port networking APIs](/build/console-features/networking/game-mesh/preferred-local-udp-multiplayer-port-networking)\
[XNetworking](/reference/networking/xnetworking/xnetworking_members)


## Related topics

- [XNetworkingRegisterPreferredLocalUdpMultiplayerPortChanged](/reference/networking/xnetworking/functions/xnetworkingregisterpreferredlocaludpmultiplayerportchanged.md)
- [XNetworking](/reference/networking/xnetworking/xnetworking_members.md)
- [XTaskQueueRegistrationToken](/reference/system/xtaskqueue/structs/xtaskqueueregistrationtoken.md)
- [Unity C# API wrappers for the GDK](/build/gdk-and-engines/unity/unity-api-wrappers.md)
- [XNetworkingPreferredLocalUdpMultiplayerPortChangedCallback](/reference/networking/xnetworking/functions/xnetworkingpreferredlocaludpmultiplayerportchangedcallback.md)
