Click here to Skip to main content
15,878,945 members
Articles / Programming Languages / C#

Outlook 2007 CPU Monitor AddIn

Rate me:
Please Sign up or sign in to vote.
4.95/5 (11 votes)
7 Oct 2009CPOL2 min read 36.7K   1.5K   19   6
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:

C#
//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.

C#
// 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:

C#
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)


Written By
Software Developer
Israel Israel
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralLooks good ... but Visual Studio 2010 on 64-bit box balks at Click Once Pin
RedDk15-Oct-10 7:46
RedDk15-Oct-10 7:46 
GeneralVery usefull Pin
Valery Possoz22-Oct-09 4:43
professionalValery Possoz22-Oct-09 4:43 
GeneralMy vote of 1 Pin
hth20007-Oct-09 7:48
hth20007-Oct-09 7:48 
GeneralRe: My vote of 1 Pin
Ron Levy7-Oct-09 20:11
Ron Levy7-Oct-09 20:11 
GeneralRe: My vote of 1 Pin
SteveKing7-Oct-09 22:39
SteveKing7-Oct-09 22:39 
GeneralRe: My vote of 1 Pin
Dean Mills8-Oct-09 1:31
professionalDean Mills8-Oct-09 1:31 

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

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