Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GTK] Use of MessageBox.Show on different threads is inconsistent #2002

Closed
Miepee opened this issue Jul 25, 2021 · 5 comments · Fixed by #2032
Closed

[GTK] Use of MessageBox.Show on different threads is inconsistent #2002

Miepee opened this issue Jul 25, 2021 · 5 comments · Fixed by #2032
Milestone

Comments

@Miepee
Copy link
Contributor

Miepee commented Jul 25, 2021

Expected Behavior

It should act like it does on WPF and Winforms.

Actual Behavior

It doesn't act like it does on Windows, and instead crashes.
This is how it looks like on Windows:
grafik
On Gtk (running under Linux), it just crashes. Sometimes it writes something to stdout, sometimes it doesn't. No consistency in what it writes.

Steps to Reproduce the Problem

  1. Call MessageBox.Show while being on a different thread

Code that Demonstrates the Problem

using Eto.Drawing;
using Eto.Forms;
using System;
using System.IO;
using System.Threading.Tasks;

namespace EtoApp1
{
    partial class MainForm : Form
    {
        void InitializeComponent()
        {
            Title = "My Eto Form";
            MinimumSize = new Size(200, 200);
            Button button = new Button() { Text = "Click Me!" };
            button.Click += Button_Click;

            Content = new StackLayout
            {
                Items =
                {
                   button
                }
            };
        }

        private async void Button_Click(object sender, EventArgs e)
        {
            await Task.Run(() => MessageBox.Show("Error"));
        }
    }
}

Specifications

  • Version: 2.5.11
  • Platform(s): Gtk, WinForms, Wpf
  • Operating System(s): Windows 10 21H1, Runnning Arch under WSL for Gtk

Haven't tested the behaviour on OSX yet.

@philstopford
Copy link
Contributor

I don't think you can reliably do anything UI-related except on the main thread. That's the reason for AsyncInvoke and similar. You might get away with it sometimes, mostly by luck, but that's the exception rather than the rule.

@Miepee
Copy link
Contributor Author

Miepee commented Jul 26, 2021

The thing is, I can do it reliably if I use either WPF or WinForms.
Considering you shouldn't normally do UI related things on non-main threads without invoking, shouldn't these platforms crash too then?

@philstopford
Copy link
Contributor

Different toolkits and different platforms have different tolerances. It's been apparent to me that GTK is the most sensitive, followed by macOS. WinForms is less sensitive than WPF, but all of them are affected by this basic assumption, that all UI activity happens on the main thread. If you throw an Invoke or AsyncInvoke around your UI command, it should improve matters considerably.

@cwensley
Copy link
Member

I concur with @philstopford. Yes, WPF and WinForms allow using a MessageBox from separate threads but Gtk and macOS do not. Both WPF and WinForms can also have UI initialized on any particular thread. They are the only platforms that allow this.

macOS will also crash if you try to show a message box from a Drawable.Paint event.

These are limitations of the respective UI frameworks. With Eto, always Invoke or AsyncInvoke UI calls to keep things working cross platform.

@Miepee
Copy link
Contributor Author

Miepee commented Jul 27, 2021

Hm, would it be possible to somehow put a warning, if you're trying to use something in a way that won't work on all platforms?
Would save some troubleshooting time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants