Skip to content

Commit ae367a1

Browse files
committed
Catch an exception
1 parent a7c40ac commit ae367a1

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

Source/NETworkManager/Controls/RemoteDesktopControl.xaml.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ private void Connect()
192192

193193
rdpClient.Connect();
194194
}
195-
195+
196196
private void Reconnect()
197197
{
198198
if (_rdpSessionInfo.AdjustScreenAutomatically)
@@ -232,7 +232,14 @@ private void FixWindowsFormsHostSize()
232232
// Source: https://msdn.microsoft.com/en-us/library/aa382170(v=vs.85).aspx
233233
private string GetDisconnectReasonFromResource(string reason)
234234
{
235-
return Application.Current.Resources[RemoteDesktopDisconnectReasonIdentifier + reason] as string;
235+
try
236+
{
237+
return Application.Current.Resources[RemoteDesktopDisconnectReasonIdentifier + reason] as string;
238+
}
239+
catch (NullReferenceException ex) // This happens when the application gets closed and the resources have already been released
240+
{
241+
return ex.Message; // The user should never see that message
242+
}
236243
}
237244

238245
private string GetDisconnectReason(int reason)
@@ -345,7 +352,7 @@ private void RdpClient_OnConnected(object sender, EventArgs e)
345352
Disconnected = false;
346353
Connected = true;
347354
}
348-
355+
349356
private void RdpClient_OnDisconnected(object sender, AxMSTSCLib.IMsTscAxEvents_OnDisconnectedEvent e)
350357
{
351358
Connected = false;

0 commit comments

Comments
 (0)