WPF and RDP Questions
- Dominant language
- C#
- Stars
- 7.7k
- Forks
- 1.3k
- Avg merge
- 1d 11h
- Merged PRs (30d)
- 61
Description
Dear WPF Team at Microsoft,
It seems like when a user reconnects to a Windows Server 2008/2016 Session using Remote Desktop (RDP protocol), this causes a call to the "OnStartup(StartupEventArgs e)" method in many WPF applications (when I say "reconnect" I mean, users do not log off but rather close the RDP session by clicking on the "X" to close the session window. Later they connect back using remote desktop - this last action causes a crash on some WPF apps. Also worth specifying that the WPF app was never closed. It was opened when they left and it crashed when they reconnected to their session).
I wanted to reach out to you all to understand if this is a bug in WPF or in Windows Server…
Short snippet of Code:
```
protected override void OnStartup(System.Windows.StartupEventArgs e)
{
base.OnStartup(e);
string AppDomainName = "My new domain";
ShutdownMode = ShutdownMode.OnLastWindowClose;
var my_domain = AppDomain.CreateDomain(AppDomainName, AppDomain.CurrentDomain.Evidence, AppDomain.CurrentDomain.SetupInformation);
CrossAppDomainDelegate MyActionLoad = () =>
{
Thread thread = new Thread(() =>
{
var app = new Application();
app.Run(); // <-- THIS CRASHES WHEN RDP IS RE-ESTABLISHED.
});
thread.SetApartmentState(ApartmentState.STA);
thread.Start();
};
my_domain.DoCallBack(MyActionLoad);
my_domain.DoCallBack(() => Application.Current.Dispatcher.Invoke(new Action(Application.Current.Shutdown)));
new Action(
() =>
{
Thread.Sleep(500);
AppDomain.Unload(my_domain);
}).BeginInvoke(null, null);
}
```
3 QUESTIONS:
Why is RDP triggering this call to OnStartup method? (And why, no matter what condition I put in the source code before it, it always crashes in the app.Run() statement, even if I check for special flags like if i write to a file and check that A signal file exists as a way to prevent calling this run method again, etc - somehow the code skips and goes directly to app.Run()).
Is this a bug in Windows Server Server 2016? (Please note that I have seen this behavior happen in Windows Server 2008, too). My server is on Microsoft Windows Server 2016 Standard (Version 10.0.14393). Is there a patch or service pack or something to fix this problem?
Any recommendation to avoid having the "app.Run()" method in the "OnStartup" to get triggered/called AFTER someone reconnects to the server via RDP?
Thank you
Contributor guide
Assessment
This issue has not been assessed yet.