private void OnClosing(ClosingReason reason, ref bool cancel) { // Check if can close window if (CanCloseWindow(reason)) { if (reason == ClosingReason.User) { _result = DialogResult.Cancel; } // Clean up _window = null; // Check if any thead is blocked during ShowDialog, then wait for it bool wait = true; while (wait) { wait = Interlocked.Read(ref _isWaitingForDialog) > 0; Thread.Sleep(1); } // Close window return; } // Supress closing cancel = true; }
/// <summary> /// Closes this dialog. /// </summary> public void Close() { if (_window != null) { var win = _window; _window = null; win.Close(); } }
/// <summary> /// Shows the dialog and waits for the result. /// </summary> /// <param name="parentWindow">The parent window.</param> /// <returns>The dialog result.</returns> public DialogResult ShowDialog(FlaxEngine.Window parentWindow) { // Show window Show(parentWindow); // Set wait flag Interlocked.Increment(ref _isWaitingForDialog); // Wait for the closing do { Thread.Sleep(1); } while (_window); // Clear wait flag Interlocked.Decrement(ref _isWaitingForDialog); return(_result); }
/// <summary> /// Shows the dialog. /// </summary> /// <param name="parentWindow">The parent window.</param> public void Show(FlaxEngine.Window parentWindow) { // Setup initial window settings CreateWindowSettings settings = CreateWindowSettings.Default; settings.Title = _title; settings.Size = Size; settings.AllowMaximize = false; settings.AllowMinimize = false; settings.HasSizingFrame = false; settings.StartPosition = WindowStartPosition.CenterParent; settings.Parent = parentWindow; SetupWindowSettings(ref settings); // Create window _window = FlaxEngine.Window.Create(settings); var windowGUI = _window.GUI; // Attach events _window.OnClosing += OnClosing; _window.OnClosed += OnClosed; // Link to the window Parent = windowGUI; // Show _window.Show(); _window.Focus(); _window.FlashWindow(); // Perform layout windowGUI.UnlockChildrenRecursive(); windowGUI.PerformLayout(); OnShow(); }
private void OnClosed() { _window = null; }