Working With AQTime From Managed Code

Applies to AQTime 8.81, last modified on March 03, 2021

To work with AQTime from managed code, add a reference to the AQTime library to your project:

  • Select Project > Add Reference from the main menu of Visual Studio. This will call the Add Reference dialog.

  • In this dialog:

    • Switch to the COM tabbed page.

    • Find SmartBear AQTime Library (TypeLib Version: 8.0) in the list of available components.

    • Choose this library in the list and click the Select button. The library will appear in the Selected Components list.

    • Press OK to close the dialog and save your changes.

After you added the reference, you will have access to AQTime’s interfaces. You can automate AQTime through both IntegrationManager and Manager objects (see Working With AQTime via COM - Overview).

The following code demonstrates using of AQTime’s IntegrationManager via COM :


using AQTime;
using System.Runtime.InteropServices;

private void AutomateAQtime()

    const string AQtimeProgID = "AQtime.AQtime.8";
    object AQtimeObject = null;
    object aParamValue = null;

    // Obtains access to AQTime
        AQtimeObject = Marshal.GetActiveObject(AQtimeProgID);
        AQtimeObject = Activator.CreateInstance(Type.GetTypeFromProgID(AQtimeProgID));

    if (AQtimeObject == null) return;

    // Obtains IAQtimeManager
    AQtime.IAQtimeManager AQtimeManager = (AQtime.IAQtimeManager)AQtimeObject;
    // Obtains IntegrationManager
    AQtime.IaqTimeIntegrationSupportManager IntegrationManager = AQtimeManager.IntegrationManager;

    // We have a reference to the integration manager.
    // Now we can use its methods and properties to automate AQTime.

    // Loads the project
    if (!IntegrationManager.OpenProject("C:\\Work\\MyVCApp\\Debug\\MyVCApp.aqt"))
        System.Windows.Forms.MessageBox.Show("Cannot open the specified project.");
        // Selects the desired profiler
        if (!IntegrationManager.SelectProfiler("Allocation Profiler"))
            System.Windows.Forms.MessageBox.Show("The specified profiler was not found.");
            // Obtains aqTimeIntegrationRunMode object for the "Normal" profiling mode
            AQtime.IaqTimeIntegrationRunMode RunMode = IntegrationManager.GetRunMode(4);

            aParamValue = null;
            // Gets the "Work Directory" parameter
            aParamValue = RunMode.GetParameterValue(2);
            // If the parameter is empty assigns a value
            if (aParamValue == null) RunMode.SetParameterValue(2, "C:\\Work");

            // Selects "Normal" profiling mode

            // Adds new module to AQTime project
            // Starts profiling and saves results to xml files
            IntegrationManager.Start("C:\\SummaryResults.xml", "C:\\ProfilingResults.xml");

            // Waits until profiling is over
            while (IntegrationManager.ProfilingStarted)

            // Removes previously added module


    // Closes AQTime

    // Releases COM objects

Please pay attention to the last three lines. They call the Marshal.ReleaseCOMObject method to release all the objects that we referred to in our code. Make sure that you call this method and release the objects. Else, the work with AQTime will not be finished properly and the next attempt to automate AQTime will fail.

See Also

Automating AQTime
Working With AQTime via COM
Working With AQTime via COM - Overview
IaqTimeIntegrationSupportManager Object

Highlight search results