Products & Services Solutions Academia Support User Community Company

Learn more about MATLAB Builder NE   

Blocking Execution of a Console Application that Creates Figures

WaitForFiguresToDie Method

The MATLAB Builder NE product adds a WaitForFiguresToDie method to each .NET class that it creates. WaitForFiguresToDie takes no arguments. Your application can call WaitForFiguresToDie any time during execution.

The purpose of WaitForFiguresToDie is to block execution of a calling program as long as figures created in encapsulated M-code are displayed. Typically you use WaitForFiguresToDie when:

When WaitForFiguresToDie is called, execution of the calling program is blocked if any figures created by the calling object remain open.

Code Fragment: Using WaitForFiguresToDie to Block Execution

The following example illustrates using WaitForFiguresToDie from a .NET application. The example uses a .NET component created by the MATLAB Builder NE product; the object encapsulates M-code that draws a simple plot.

  1. Create a work folder for your source code. In this example, the folder is D:\work\plotdemo.

  2. In this folder, create the following M-file:

    drawplot.m
    
    function drawplot()
        plot(1:10);
    
  3. Use MATLAB Builder NE to create a .NET component with the following properties:

    Component nameFigure
    Class namePlotter

  4. Create a .NET program in a file named runplot with the following code:

    using Figure.Plotter;
    
    public class Main {
    		public static void main(String[] args) {
    				try {
    						plotter p = new Plotter();
    						try {
    								p.showPlot();
    								p.WaitForFiguresToDie();
    						}
    					catch (Exception e) {
    						console.writeline(e);
                  }  
    				}
           }
    		}	
  5. Compile the application.

    When you run the application, the program displays a plot from 1 to 10 in a MATLAB figure window. The application ends when you dismiss the figure.

      Note   To see what happens without the call to WaitForFiguresToDie, comment out the call, rebuild the application, and run it. In this case, the figure is drawn and is immediately destroyed as the application exits.

  


Recommended Products

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.

 © 1984-2009- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS