Desktop Duplication API is unable to capture desktop frames with Windows 10

Setup Details
Windows-10 Pro
Version-21H2
OS build-19044.2075
Windows Feature Experience Pack 120.2212.4180.0
NVIDIA Tesla M60
Driver Version- 512.78
CUDA Version- 11.6

I am trying to capture desktop display using DDA API’s and able to do that first time, but when i try reconnect DDA APi’s it throws error.

Same workflow works on Windows 2016 Server machine.

I am getting below error

DesktopApplication::InitDup: Line 150, Returning error 0x8000ffff

DesktopApplication::Init: Line 235, Returning error 0x8000ffff

Initialization failed with error 0x8000ffff

any help would be greatly appreciated

Also providing sample program to reproduce this issue

nvEncDXGIOutputDuplicationSample.exe (74.5 KB)

https://github.com/NVIDIA/video-sdk-samples/tree/master/nvEncDXGIOutputDuplicationSample

Above given executable and link to sample program tried on windows 10

Steps to reproduce :

  1. connect to Windows 10 using RDP client
  2. run sample program nvEncDXGIOutputDuplicationSample.exe -frames 60
  3. it will generate DDATest_0.H264 file which can be played in any player.
  4. disconnect and connect again to Windows 10
  5. run sample program again
  6. you will error now

c:>nvEncDXGIOutputDuplicationSample.exe -frames 60
DXGIOUTPUTDuplication_NVENC_Demo: Frames to Capture: 60.
DemoApplication::InitDup: Line 125, File C:\mohit\video-sdk-samples-master\video-sdk-samples-master\nvEncDXGIOutputDuplicationSample\main.cpp Returning error 0x8000ffff
DemoApplication::Init: Line 212, File C:\mohit\video-sdk-samples-master\video-sdk-samples-master\nvEncDXGIOutputDuplicationSample\main.cpp Returning error 0x8000ffff
Initialization failed with error 0x8000ffff