Click here to Skip to main content
Click here to Skip to main content

Outlook 2007 CPU Monitor AddIn

, 7 Oct 2009
Rate this:
Please Sign up or sign in to vote.
A cool CPU Monitor AddIn for Outlook 2007
CPUMonitorAddInSetup

Introduction

This Addin for Outlook 2007 adds a custom task pane that monitors the CPU and memory usage for the local machine or a remote machine, condition to your permissions on that remote machine. This is a sample for a cool VSTO implementation inside Outlook 2007. The Monitor control is a control from Niel M.Thomas' article A thermometer control, so thank you Niel.

The Addin adds a button to the standard toolbar on Outlook Explorer name "CPU Monitor". You can launch as many task panes as you want and connect each one to a different machine. The machine name is stored in an XML file in your temp directory, each time Outlook opens, the XML file is loaded and your setting for the Addin is preserved. The two buttons at the bottom of the custom task pane launch the Remote Desktop Connection on to the computer that is assigned to the task pane, or launch the computer management console connected to the same computer.

Background

Office Business Applications (OBA) are an emerging breed of applications that leverage the power of the Office Business Platform, that is, the clients, servers, services, and tools that comprise the 2007 Microsoft Office system. That said, this Addin will help you monitor a computer/server for high CPU or memory usage from inside Microsoft Outlook 2007. The Addin was developed with VS 2008 and VSTO 3.1.

Using the Code

First, we need to create a VSTO project for Outlook 2007 and add a user control to our project.
Next, we start working on our user control. In this user control, I added Niel's Thermometer control and a prefCounter to monitor the CPU and memory of a machine. I configure the prefCounter to the "% Processor Time" for the CPU and another one to "Committed Bytes" for the memory usage. I started a Timer control to check these properties each sec.

Here is the Tick event for the Timer control:

//calculate the values of the monitors.
int num = Convert.ToInt32(Math.Ceiling((double)this.perfCounter.NextValue()));
cpuMonitor1.Value = (float)num;
toolTip1.SetToolTip(cpuMonitor1, num.ToString() + "%");
int maxMemory = Convert.ToInt32(Math.Round((double)this.perfCounter2.NextValue() / 
	Math.Pow(1024, 2)));
cpuMonitor2.Max = maxMemory;
cpuMonitor2.Interval = maxMemory / 10;
int memory = Convert.ToInt32(Math.Ceiling((double)this.perfCounter1.NextValue()) / 
	Math.Pow(1024, 2));
cpuMonitor2.Value = (float)memory; 
toolTip1.SetToolTip(cpuMonitor2,"Commit Charge: "+ memory.ToString()+"M / " + 
	maxMemory.ToString()

Next, we need to add our button to the Outlook Explorer standard toolbar.

// Create the button in the standard toolbar.
newButton = (Microsoft.Office.Core.CommandBarButton)
this.Application.ActiveExplorer().CommandBars["standard"].Controls.Add(
	Microsoft.Office.Core.MsoControlType.msoControlButton,
	missing, missing, missing, missing);
newButton.Caption = "CPU Monitor";
newButton.Style = Microsoft.Office.Core.MsoButtonStyle.msoButtonCaption;
newButton.Picture = MyHost.GettIPictureDispFromPicture
	(Properties.Resources.control_panel); 
newButton.Tag = "CPUMonitor";
newButton.Click += new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler
			(this.newButton_Click);

Now, let's look at the button click event:

myUserControl1 = new CPUMonitor(computerName,ds);
myCustomTaskPane = this.CustomTaskPanes.Add(myUserControl1, "CPU Monitor Task Pane");
myCustomTaskPane.DockPosition = Office.MsoCTPDockPosition.msoCTPDockPositionRight;
//myCustomTaskPane.Height = 500;
myCustomTaskPane.Width = 195;
myCustomTaskPane.DockPositionRestrict =
	Office.MsoCTPDockPositionRestrict.msoCTPDockPositionRestrictNoHorizontal;
myCustomTaskPane.VisibleChanged += new EventHandler(myCustomTaskPane_VisibleChanged); 
myCustomTaskPane.Visible = true;

That's it. All the other stuff inside the code is for reading the XML file into a DataSet and using it to determine which computer to connect to, and if we need to show the task pane next time Outlook opens or not.

Points of Interest

This is a cool usage of VSTO and Outlook Addin.
Hope you will learn from it and develop more fun and cool Addins for Office.

Again, thank you Niel, VERY COOL CONTROL!

History

  • 7th October, 2009: Initial post

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Ron Levy
Software Developer
Israel Israel
No Biography provided
Follow on   Twitter

Comments and Discussions

 
GeneralLooks good ... but Visual Studio 2010 on 64-bit box balks at Click Once PinmemberRedDK15-Oct-10 7:46 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web01 | 2.8.140721.1 | Last Updated 7 Oct 2009
Article Copyright 2009 by Ron Levy
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid