// This method is fired on connection status events
private void OnConnectionStatusUpdate(object sender, ConnectionStatusEventArgs e)
{
// For multi-threading reasons, work with a copy of the ConnectionStatusEventArgs to prevent situations in which the EventArgs may already be ahead of us while in the middle processing it.
// This accomplishes the same goal as locking a collection to prevent in-flight changes from affecting outcomes
ConnectionStatusEventArgs eCopy = e;
/* Dispatcher.InvokeAsync() is needed for multi-threading considerations. When processing events outside of the UI thread, and we want to
influence the UI .InvokeAsync() allows us to do so. It can also help prevent the UI thread from locking up on long operations. */
Dispatcher.InvokeAsync(() =>
{
outputBox.AppendText(string.Format("{1} Status: {2}",
Environment.NewLine,
eCopy.Connection.Options.Name,
eCopy.Status));
});
}