private static void ClickExceptionButton(ControlExceptions controlExceptions) { try { Exception exception; Button removeButton; lock (_syncObj) { exception = controlExceptions.Exceptions.Count > 0 ? controlExceptions.Exceptions.Dequeue() : null; if (controlExceptions.Exceptions.Count == 0) { _controlExceptions.Remove(controlExceptions.Control); removeButton = controlExceptions.Button; controlExceptions.Button = null; } else { removeButton = null; } } if (removeButton != null) { try { controlExceptions.Control.OnUiThread(removeButton.Dispose); } catch { } } else { controlExceptions.Control.OnUiThread(() => UpdateButton(controlExceptions)); } if (exception != null) { Mbox.Error(exception, "Sorry! We could not load the data you wanted."); } } catch { } }
public static void SetException(this Control control, Exception exception) { try { ControlExceptions controlExceptions; bool added; lock (_syncObj) { if (_controlExceptions.TryGetValue(control, out controlExceptions)) { added = false; } else { added = true; controlExceptions = new ControlExceptions(control); _controlExceptions.Add(control, controlExceptions); } } controlExceptions.Exceptions.Enqueue(exception); if (added) { control.OnUiThread(() => { Button showExceptionButton = CreateShowExceptionButton(control); lock (_syncObj) { controlExceptions.Button = showExceptionButton; UpdateButton(controlExceptions); } showExceptionButton.Click += (s, e) => ClickExceptionButton(controlExceptions); }); } else { control.OnUiThread(() => UpdateButton(controlExceptions)); } } catch { } }
private static void UpdateButton(ControlExceptions controlExceptions) { try { lock (_syncObj) { if (controlExceptions.Button != null) { controlExceptions.Button.Text = $"Show exception... ({controlExceptions.Exceptions.Count})"; controlExceptions.Button.BringToFront(); } } } catch { } }