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.
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
prefCounterto monitor the CPU and memory of a machine. I configure the
prefCounterto 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
Tickevent for the Timer control:
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() /
cpuMonitor2.Max = maxMemory;
cpuMonitor2.Interval = maxMemory / 10;
int memory = Convert.ToInt32(Math.Ceiling((double)this.perfCounter1.NextValue()) /
cpuMonitor2.Value = (float)memory;
toolTip1.SetToolTip(cpuMonitor2,"Commit Charge: "+ memory.ToString()+"M / " +
Next, we need to add our button to the Outlook Explorer standard toolbar.
newButton = (Microsoft.Office.Core.CommandBarButton)
missing, missing, missing, missing);
newButton.Caption = "CPU Monitor";
newButton.Style = Microsoft.Office.Core.MsoButtonStyle.msoButtonCaption;
newButton.Picture = MyHost.GettIPictureDispFromPicture
newButton.Tag = "CPUMonitor";
newButton.Click += new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler
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.Width = 195;
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
DataSetand 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!
- 7th October, 2009: Initial post