ArgusMagnus Posted September 27, 2015 Share Posted September 27, 2015 I know I read the solution somewhere some time ago but I can't remember where.. What is the recommended way to execute a method on the UI Thread, e.g. for showing a MessageBox? Im currently going with Process process = Process.GetCurrentProcess(); Form form = Form.FromHandle(process.MainWindowHandle) as Form; form?.Invoke(new Action(() => { MessageBox.Show("Some Message"); })); But this seems a bit ugly.. Quote My batch Image Processor: https://imagenator.codeplex.com Link to comment Share on other sites More sharing options...
MJW Posted September 27, 2015 Share Posted September 27, 2015 void ShowMessage(string msg, string caption) { PaintDotNet.Threading.PdnSynchronizationContext.Instance.Send( new System.Threading.SendOrPostCallback(delegate(object state) { // This line runs on the UI thread and not on the Render thread System.Windows.Forms.MessageBox.Show(msg, caption); }), null); } 1 Quote Link to comment Share on other sites More sharing options...
ArgusMagnus Posted September 27, 2015 Author Share Posted September 27, 2015 This was exactly what I was looking for, thanks Quote My batch Image Processor: https://imagenator.codeplex.com Link to comment Share on other sites More sharing options...
MJW Posted September 28, 2015 Share Posted September 28, 2015 Thanks, ArgusMagnus. I'm glad I remembered where to find it. I'm also glad the subject now has a thread with a clearly related title, since it will make it easier to find in the future. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.