Click here to get the sample associated with this walkthrough.
In this topic
- Creating a project in Visual Studio
- Setting additional Extension properties
- Adding the Timer functionality
- Compiling the project
- Using the add-in in ArcGIS Explorer
- Debugging the add-in
Creating a project in Visual Studio
Extensions are a type of ArcGIS Explorer customization that do not rely on user interaction. Instead, extensions can be used to run code in response to the application starting or shutting down. Extensions automatically run when the application starts and have a life span that is tied to the life span of the application. Extensions have no user interface (UI). The easiest way to create an Extension is to use the templates provided with this software development kit (SDK).
Do the following steps to create an Extension that fires an event (a message box) at set intervals:
- Start Visual Studio.
While this topic refers to and shows screen shots from Visual Studio 2008 running on Windows Vista, you can also follow the steps in Visual Studio 2010, Visual Basic or Visual C# Express, and Windows XP or Windows 7.
- Click File, click New, and click New Project. The New Project dialog box appears.
To complete this scenario, use C# or VB .NET. The code for both is shown; however, this topic only shows the C# dialog boxes in the screen shots, since the dialog boxes and views you interact with in VB .NET are very similar.
- On the New Project dialog box, click the Visual C# or Visual Basic Projects node under the Project types pane, click the ArcGIS node, then click the Explorer node.
- Click the ArcGIS Explorer Extension template under the Templates pane.
- Name the project ExtensionWalkthrough, then click Browse to locate where you want to save the project. See the following screen shot:
- Click OK on the New Project dialog box to create the project. The New ArcGIS Explorer Extension Project dialog box appears where you can set additional properties for your extension.
Setting additional Extension properties
Do the following steps to set additional Extension properties:
-
On the New ArcGIS Explorer Extension Project (Enter Project Settings) dialog box, the Name property is automatically added. In the Description, Group Caption (displays on the Add-Ins tab), and Publisher text boxes, type an appropriate name. See the following screen shot:
-
Click Next on the preceding dialog box. The second page (Enter Extension Settings) of the New ArcGIS Explorer Extension Project dialog box appears. See the following screen shot:
-
Type a caption, for example, ExtensionWalkthrough in the Caption text box. Although Extensions do not have a UI button component, you need the caption to use in the ArcGIS Explorer Add-Ins Manager dialog box.
-
Click Finish.
Conditions (availability) are not accessible to use with Extensions.
Adding the Timer functionality
Do the following steps to add the Timer functionality:
- Double-click the Extension.cs class in the Solution Explorer to view the template code.
- Insert the following code example:
class Extension: ESRI.ArcGISExplorer.Application.Extension
{
System.Timers.Timer _t = new System.Timers.Timer(60000);
public override void OnStartup()
{
_t.Start();
_t.Elapsed += new System.Timers.ElapsedEventHandler(_t_Elapsed);
}
void _t_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
System.Windows.Forms.MessageBox.Show(
"This message box is displayed every 60 seconds. If you would like to disable this extension, go to the ArcGIS Explorer Options, select the Resources tab, and Manage Add-Ins.");
}
public override void OnShutdown()
{
_t.Stop();
}
}
[VB.NET]
Friend Class Extension
Inherits ESRI.ArcGISExplorer.Application.Extension
Private _t As System.Timers.Timer = New System.Timers.Timer(60000)
Public Overrides Sub OnStartup()
_t.Start()
AddHandler _t.Elapsed, AddressOf _t_Elapsed
End Sub
Private Sub _t_Elapsed(ByVal sender As Object, ByVal e As System.Timers.ElapsedEventArgs)
System.Windows.Forms.MessageBox.Show("This message box is displayed every 60 seconds. If you would like to disable" + _
"this extension, go to the ArcGIS Explorer Options, select the Resources tab, and Manage Add-Ins.")
End Sub
Public Overrides Sub OnShutdown()
_t.Stop()
End Sub
End Class
Compiling the project
Do the following steps to build your project:
- Save your project.
- Click the Build menu and click Build Solution.
- If your project built correctly, a report states the build succeeded in the Output window at the bottom of the Visual Studio .NET integrated development environment (IDE).
You can also check the results of the build operation by reviewing the subdirectories of your project. By default, you will build a debug version of your project. The dynamic-link library (DLL) that results from the build operation will be stored in the Bin\Debug subdirectory of your project. This directory also contains debug information (.pdb) and a type library (.tlb) file, produced by the Assembly Registration tool.
The obj subdirectory of the project directory contains temporary files used by the compiler and Visual Studio.
The obj subdirectory of the project directory contains temporary files used by the compiler and Visual Studio.
- If you successfully followed this walkthrough, your build will succeed. Close Visual Studio now that your extension has been created. If your build operation did not succeed, click View and click Task List to view the errors, correct the errors as indicated, then close Visual Studio when you have a successful build.
If you double-click the task, the line of code causing the error is automatically selected.
On a successful build, the necessary files are automatically added to the following locations:
- For Windows Vista and Windows 7—C:\Users\<username>\AppData\Roaming\ESRI\ArcGIS Explorer\Addins.
- For Windows XP—C:\Documents and Settings\<username>\Application Data\ESRI\ArcGIS Explorer\AddIns.
Using the add-in in ArcGIS Explorer
Do the following steps to use the extension in ArcGIS Explorer:
- Start ArcGIS Explorer.
- The extension automatically runs behind the scene. You will not see the extension on the Add-Ins tab.
Debugging the add-in
Running the add-in in debug mode allows you to step through the code when it is executed. This is helpful when you encounter bugs in custom add-ins. If you followed the steps in this topic, you should not have to debug the add-in you have created in this walkthrough. However, for more information about debugging add-ins, see How to debug add-ins in Visual Studio.
See Also:
Sample: Extension WalkthroughHow to debug add-ins in Visual Studio