MahApps.Metro icon indicating copy to clipboard operation
MahApps.Metro copied to clipboard

Me.ShowMessageAsync and MultiThreading

Open clementpoiret opened this issue 11 years ago • 2 comments

Hi,

I'm actually trying in VB.Net to start another thread but it seems impossible if I show a MahApps message box inside like this :

Private Sub MySub (MyCode...) Try (...) Me.ShowMessageAsync("Title","text") Catch Ex As Exception Me.ShowMessageAsync("Title","text") End Try End Sub

capture d ecran 3

clementpoiret avatar Apr 28 '15 17:04 clementpoiret

That is how multi-threading works in the .NET Framework.

You have the UI thread, on which your window and all the elements inside are running. There is also your own thread where you are probably doing some CPU-intensive work. This second thread cannot access the UI thread because the UI thread owns that window and accessing it might cause other exceptions.

See StackOverflow for further details. The accepted answer would in VB.NET be

Me.Dispatcher.BeginInvoke(Sub()
                              Me.ShowMessageAsync("Title", "Text")
                          End Sub)

Dotnetifier avatar Apr 29 '15 07:04 Dotnetifier

Thank you so much ! :D

clementpoiret avatar Apr 29 '15 08:04 clementpoiret