Encapsulating Matlab's Mouse Control Functions for C#

33 Views Asked by At

When I embed Matlab windows into C#, I use C# to call the mouse functions such as drawline() and getpts() which are encapsulated in Matlab's dll, and then the program crashes, how can I solve this problem?

ps: The functions that I call in C# can be executed in Matlab.

ps: If I don't embed the window into C#, but just let C# call the Matlab function, it can execute the mouse control normally in the window, but once embedded into the C# window, it will crash when execute the mouse command.

I want the window to be embedded in C# and to execute mouse control type functions correctly in the window.

1

There are 1 best solutions below

1
徐永承 On

I solved this problem by using an asynchronous thread (async). The reason it happens is that it gets stuck with the C# UI thread. For example,

private async void btnShowHeight_Click(object sender, EventArgs e)
{
    Task taskImshow = Task.Run(() =>
    {
        matlabDllClass.imshow(0, figMainNum, mwdataHeight2D, new MWNumericArray());
    });
    await taskImshow;
}