Context
Before to dive into the issue, I first need to indicate that I'm trying to display a matlab modal figure when clicking some button in a winforms application.
The matlab code for displaying the figure is easy and works all fine in matlab environment (i.e. the figure is modal and I cannot click anywhere else as expected):
function [] = ShowModalDlg()
%[
% Create a modal figure
fig = figure('WindowStyle', 'modal');
% Add some drawings in it
membrane();
% Block execution until figure gets closed.
uiwait(fig);
%]
Compiling matlab code to .NET and integrating it into my winforms application is easy too (just need to use the Matlab Compiler SDK):
private void onBtnClick(object sender, EventArgs e)
{
matlabComponent.ShowModalDlg();
}
Issue
When clicking the button in my winforms application, everything seems to work fine:
- The matlab figure popups as expected.
- The figure stays on top and I cannot click anywhere else (i.e. modal behavior).
- The winforms thread really blocks in
matlabComponent.ShowModalDlg()until closing the figure before to continue with next lines of code.
But, because there's a but, it is all like the winform application is still continuing to enqueue UI events and when I close the matlab figure they are all processed in a row. For instance, while the matlab figure is displayed, if I try to move the winform that hold the button nothing happens, but as soon as I close the figure, the below winform moves!!
I suspect matlab-side to use different dispaching model or whatever (this is java in the background) ... anyway I'd like to block winforms to workaround this issue, for instance something like:
private void onBtnClick(object sender, EventArgs e)
{
using(var oo = new DiscardUIEvents(this))
{
matlabComponent.ShowModalDlg();
}
}
Is this possible ?