> ## 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.

# XLaunchNewGame

> XLaunchNewGame

# XLaunchNewGame

结束当前游戏、释放已分配的所有资源，然后启动新游戏。

## Syntax

```cpp theme={null}
void XLaunchNewGame(  
         const char* exePath,  
         const char* args,  
         XUserHandle defaultUser  
)  
```

### Parameters

*exePath*   \_In\_z\_\
类型：char\*

要启动的新游戏的路径和文件名。此路径可以相对于当前目录，也可以是绝对路径。需要知道调用可执行文件路径的游戏可以调用 [GetModuleFileNameA](https://learn.microsoft.com/windows/win32/api/libloaderapi/nf-libloaderapi-getmodulefilenamea)，并将模块句柄设置为 nullptr。

*args*   \_In\_opt\_z\_\
类型：char\*

用于启动新游戏的任何适用的、特定于游戏的参数。

*defaultUser*   \_In\_opt\_\
类型：XUserHandle

启动新游戏的用户的句柄。如果未指定值，则指定当前用户。

### Return value

类型：void

此函数不返回值，也不引发异常，即使无法重启游戏也是如此。

## Remarks

<Note>此函数在时间敏感型线程上调用是不安全的。有关详细</Note>
信息，请参阅[时间敏感型线程](https://learn.microsoft.com/gaming/gdk/docs/gdk-dev/console-dev/overviews/threads/time-sensitive-threads)。

此函数会重启游戏，结束游戏的当前进程，并使用新进程重启游戏。游戏会在不重启其运行所在的虚拟机的情况下重启。你可以选择指定不同的默认用户以及用于重启游戏的特定于游戏的参数；有关指定不同默认用户的详细信息，请参阅[用户身份和 XUser](/build/core-features/common/user/player-identity-xuser)。

即使函数在启动新游戏时遇到错误，当前进程也始终会被终止。例如，如果为 *exePath*、*args* 或 *defaultUser* 指定的任何值无效，该函数将不返回值，也不引发异常。

<Note>调用此函数后，所有以前挂载的 DLC 都将</Note>
被卸载，但托管 **XLaunchNewGame** 目标的 DLC 除外。**G:** 驱动器将继续指向基础包的根目录，而不是新启动的 EXE。

<Note>如果调用 **XLaunchNewGame** 后但在新启动的游戏设置其挂起处理程序之前游戏被挂起，</Note>
则该游戏将被终止。这是一个非常狭窄的时间窗口，实际发生的可能性极低。

<Note>使用 [XMemTransferMemory (NDA topic)](/reference/system/xmem/functions/xmemtransfermemory) 传输到系统的内存将被保留。</Note>

## Requirements

**头文件：** XGame.h

**库：** xgameruntime.lib

**受支持的平台：** Windows、XBOX One 系列主机和 XBOX Series 主机

## Conceptual documentation

* [时间敏感型线程](https://learn.microsoft.com/gaming/gdk/docs/gdk-dev/console-dev/overviews/threads/time-sensitive-threads)
* [支持游戏即服务 (GaaS)](/build/core-features/common/packaging/supporting-games-as-a-service)

## See also

[XGame](/reference/system/xgame/xgame_members)\
[用户身份和 XUser](/build/core-features/common/user/player-identity-xuser)\
[XLaunchUri](/reference/system/xlauncher/functions/xlaunchuri)


## Related topics

- [XLaunchRestartOnCrash](/zh-CN/reference/system/xgame/functions/xlaunchrestartoncrash.md)
- [更改游戏的默认用户](/zh-CN/build/core-features/common/user/users-changing-default-user.md)
- [XGame](/zh-CN/reference/system/xgame/xgame_members.md)
- [支持游戏即服务(GaaS)](/zh-CN/build/core-features/common/packaging/supporting-games-as-a-service.md)
- [用户与输入设备](/zh-CN/build/core-features/common/user/users-input-devices.md)
