Reputation: 138
I have issue: One thread raises event that is listened from main thread. Main thread in eventHandler raises message dialog like this:
MessageDialog md = new MessageDialog (parent_window, flags, msgtype, btntype, msg);
md.Run ();
md.Destroy();
However application crashes on md.Run(); (if i raise messageDialog using gtk.application.invoke() there is no crash but there is also no modality in dialog.)
Upvotes: 1
Views: 335
Reputation: 16153
GTK objects can only be accessed safely from the main thread. If you subscribe to an event from the main thread, that does not mean that the event will be raised from the main thread. Events are raised on the thread that raises them.
What you need to do is to use Application.Invoke to safely queue a delegate on the main thread's mainloop, and access the GUI objects from that delegate. You can do this in the event handler, or you could even use a delegate to dispatch the event onto the main thread, so that event handlers would not have to do so - it's just a question of how you want to define your internal API.
Note that although Application.Invoke runs the delegate asynchronously, this does not affect the modality of the dialog. The thing that affects the modality of the dialog is whether you include the DialogFlags.Modal flag in the flags parameters.
Upvotes: 1