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

# XNetworkingUnregisterPreferredLocalUdpMultiplayerPortChanged

> XNetworkingUnregisterPreferredLocalUdpMultiplayerPortChanged

Unregisters a callback function that was registered with [XNetworkingRegisterPreferredLocalUdpMultiplayerPortChanged](https://docs.xbox.com/reference/networking/xnetworking/functions/xnetworkingregisterpreferredlocaludpmultiplayerportchanged.md).

## Syntax

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

### Parameters

*token*   \_In\_\
Type: [XTaskQueueRegistrationToken](https://docs.xbox.com/reference/system/xtaskqueue/structs/xtaskqueueregistrationtoken.md)

The token returned from [XNetworkingRegisterPreferredLocalUdpMultiplayerPortChanged](https://docs.xbox.com/reference/networking/xnetworking/functions/xnetworkingregisterpreferredlocaludpmultiplayerportchanged.md).

*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).

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](https://docs.xbox.com/reference/networking/xnetworking/functions/xnetworkingpreferredlocaludpmultiplayerportchangedcallback.md) if *wait* is true since this will deadlock.

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](https://docs.xbox.com/reference/networking/xnetworking/functions/xnetworkingquerypreferredlocaludpmultiplayerport.md)\
[Preferred local UDP multiplayer port networking APIs](https://docs.xbox.com/build/console-features/networking/game-mesh/preferred-local-udp-multiplayer-port-networking.md)\
[XNetworking](https://docs.xbox.com/reference/networking/xnetworking/xnetworking_members.md)


## Related topics

- [XNetworkingRegisterPreferredLocalUdpMultiplayerPortChanged](https://docs.xbox.com/reference/networking/xnetworking/functions/xnetworkingregisterpreferredlocaludpmultiplayerportchanged.md)
- [XNetworking (API contents)](https://docs.xbox.com/reference/networking/xnetworking/xnetworking_members.md)
- [XTaskQueueRegistrationToken](https://docs.xbox.com/reference/system/xtaskqueue/structs/xtaskqueueregistrationtoken.md)
- [Using C# wrappers for GDK APIs in your Unity project](https://docs.xbox.com/build/gdk-and-engines/unity/unity-api-wrappers.md)
- [Preferred UDP multiplayer port](https://docs.xbox.com/build/console-features/networking/game-mesh/preferred-local-udp-multiplayer-port-networking.md)
