Vyoms OneStopTesting.com - Testing EBooks, Tutorials, Articles, Jobs, Training Institutes etc.
OneStopGate.com - Gate EBooks, Tutorials, Articles, FAQs, Jobs, Training Institutes etc.
OneStopMBA.com - MBA EBooks, Tutorials, Articles, FAQs, Jobs, Training Institutes etc.
OneStopIAS.com - IAS EBooks, Tutorials, Articles, FAQs, Jobs, Training Institutes etc.
OneStopSAP.com - SAP EBooks, Tutorials, Articles, FAQs, Jobs, Training Institutes etc.
OneStopGRE.com - of GRE EBooks, Tutorials, Articles, FAQs, Jobs, Training Institutes etc.
Bookmark and Share Rss Feeds

Creating an Oracle 10gR2 System Tray Application Controller | Articles | Recent Articles | News Article | Interesting Articles | Technology Articles | Articles On Education | Articles On Corporate | Company Articles | College Articles | Articles on Recession
Sponsored Ads
Hot Jobs
Fresher Jobs
Experienced Jobs
Government Jobs
Walkin Jobs
Placement Section
Company Profiles
Interview Questions
Placement Papers
Resources @ VYOMS
Companies In India
Consultants In India
Colleges In India
Exams In India
Latest Results
Notifications In India
Call Centers In India
Training Institutes In India
Job Communities In India
Courses In India
Jobs by Keyskills
Jobs by Functional Areas
Learn @ VYOMS
GATE Preparation
GRE Preparation
GMAT Preparation
IAS Preparation
SAP Preparation
Testing Preparation
MBA Preparation
News @ VYOMS
Freshers News
Job Articles
Latest News
India News Network
Interview Ebook
Get 30,000+ Interview Questions & Answers in an eBook.
Interview Success Kit - Get Success in Job Interviews
  • 30,000+ Interview Questions
  • Most Questions Answered
  • 5 FREE Bonuses
  • Free Upgrades

VYOMS TOP EMPLOYERS

Wipro Technologies
Tata Consultancy Services
Accenture
IBM
Satyam
Genpact
Cognizant Technologies

Home » Articles » Creating an Oracle 10gR2 System Tray Application Controller

Creating an Oracle 10gR2 System Tray Application Controller








Article Posted On Date : Wednesday, September 8, 2010


Creating an Oracle 10gR2 System Tray Application Controller
Advertisements

Creating an Oracle 10gR2 System Tray Application Controller


Creating an application to sit in your system tray is much easier than you may think and to prove this point I will provide a step by step example of controlling an Oracle 10gR2 database service.

Introduction

I do a lot of that is targeted toward an Oracle instance thus I have an installation of Oracle 10gR2 on my  If you fall into this category as well I am sure that you will agree that oracle can consume a great deal of resources which can place a significant drag on your I realize that I may be in the minority here but it irritates me that my system seems sluggish because of the oracle service.

Now I also realize that I can set the service to a manual startup or even possibly created a batch file to stop and start this service but I wanted a solution that would allow me to quickly determine if this service is running or not. Thus the idea of using the system tray hit me.

Getting Started

Open Visual Studio and create a new Windows Application project and provide a meaningful name, in this case I have used Oracle Service Controller.


Figure 1

The next step is to add a new class named MainClass to this project and add the appropriate references as indicated below.


01.using System;
02.using System.Diagnostics;
03.using System.Text;
04.using System.Timers;
05.using System.Windows.Forms;
06.using System.ServiceProcess;
07.using System.Drawing;
08.using System.Reflection;
09.using System.Configuration;
10. 
11.namespace OracleServiceControler
12.{
13.    public class MainClass {}
14.}

In this example we will be working with a NotifyIcon ContextMenu, Timer, and ServiceController object so we need to go ahead and declare these objects.


1.private NotifyIcon _notifyIcon = null;
2.private ContextMenu _contextMenu = null;
3.private System.Timers.Timer _timer = null;
4.private ServiceController _oracleDatabaseServiceController = null;

The next step in to esablish a Main method which will fire when the application is executed.


1.public static void Main(string[] args)
2.{
3.  MainClass _main = new MainClass();
4.  _main.StartApplication();
5.}

You will probably notice that in the above code I am calling a method named StartApplication, this method is the core of the  and perform numerous actions. I am going to break down each of these actions into section in hope that the example is easier to follow.

StartApplication Method Explained

At the core of this application we need to accomplish the following:

  1. Pull in the application settings from the app.config.
  2. Create the ServiceController object.
  3. Create the NotifyIcon object.
  4. Create the ContextMenu object.

01.public void StartApplication()
02.{
03.  try
04.  {
05.    string _serviceName =
06.          ConfigurationManager.AppSettings["Oracle_Service_Name"];
07.    string _tooltip = ConfigurationManager.AppSettings["Notify_Icon_Tooltip"];
08.    _oracleDatabaseServiceController = new ServiceController(_serviceName);
09. 
10.    _notifyIcon = new NotifyIcon();
11.    _notifyIcon.Visible = false;
12.    _notifyIcon.Text = _tooltip;
13. 
14.    _contextMenu = new ContextMenu();
15. 
16.    CreateMenu();
17. 
18.    _notifyIcon.ContextMenu = _contextMenu;
19. 
20.    SetUpTimer();
21. 
22.    _timer.Elapsed += new ElapsedEventHandler(TimerElapsed);
23. 
24.    _notifyIcon.Visible = true;
25. 
26.    GetServiceStatus();
27. 
28.    Application.Run();
29.  }
30.  catch (Exception ex)
31.  {
32.    MessageBox.Show(ex.Message.ToString(), "Oracle Service Controller",
33.      MessageBoxButtons.OK, MessageBoxIcon.Error);
34.  }
35.}

CreateMenu Method Explained

If you are not familiar with a ContextMenu take a moment to read the MSDN Documention. Basically a context menu is nothing more than a shortcut menu and if you have ever right clicked on any of the that may be sitting in your system tray you have used a context menu.

Next I will create my ContextMenu which will contain the following five items:

  1. Stop
  2. Start
  3. Spacer
  4. About
  5. Exit

01.public void CreateMenu()
02.{
03.  try
04.  {
05.    _contextMenu.MenuItems.Add(new MenuItem("Stop",
06.        new EventHandler(StopService)));
07.    _contextMenu.MenuItems.Add(new MenuItem("Start",
08.        new EventHandler(StartService)));
09. 
10.    _contextMenu.MenuItems.Add("-");
11. 
12.    _contextMenu.MenuItems.Add(new MenuItem("About",
13.        new EventHandler(AboutDisplay)));
14.    _contextMenu.MenuItems.Add(new MenuItem("Exit",
15.        new EventHandler(ExitController)));
16.  }
17.  catch (Exception ex)
18.  {
19.    MessageBox.Show(ex.Message.ToString(), "Oracle Service Controller",
20.      MessageBoxButtons.OK, MessageBoxIcon.Error);
21.  }
22.}

SetupTimer Explained

The timer we will use serves only one purpose which is to change the state of the NotifyIcon based upon the ServiceController status.


01.private void SetUpTimer()
02.{
03.  try
04.  {
05.    _timer = new System.Timers.Timer();
06.    _timer.AutoReset = true;
07.    _timer.Interval = 5000;
08.    _timer.Start();
09.  }
10.  catch (Exception ex)
11.  {
12.    MessageBox.Show(ex.Message.ToString(), "Oracle Service Controller",
13.      MessageBoxButtons.OK, MessageBoxIcon.Error);
14.  }
15.}

As the timer has elapsed we need to get the status of the ServiceController. This is accomplished by the following method.


01.public void TimerElapsed(object sender, System.Timers.ElapsedEventArgs e)
02.{
03.  try
04.  {
05.    GetServiceStatus();
06.  }
07.  catch (Exception ex)
08.  {
09.    throw;
10.  }
11.}

GetServiceStatus Method Explained

In this method I determine the status of the service, set the appropriate icon, and build the context menu.


01.private void GetServiceStatus()
02.{
03.  try
04.  {
05.    _oracleDatabaseServiceController.Refresh();
06. 
07.    if (_oracleDatabaseServiceController.Status ==
08.        System.ServiceProcess.ServiceControllerStatus.Running)
09.    {
10.      Icon _startedIcon =
11.    GetIcon("OracleServiceControler.raddevoraserviceon.ico");
12.      _notifyIcon.Icon = _startedIcon;
13. 
14.      _contextMenu.MenuItems[0].Enabled = true;
15.      _contextMenu.MenuItems[1].Enabled = false;
16.      _contextMenu.MenuItems[2].Enabled = true;
17.      _contextMenu.MenuItems[3].Enabled = true;
18.      _contextMenu.MenuItems[4].Enabled = true;
19.    }
20.    else if (_oracleDatabaseServiceController.Status ==
21.        System.ServiceProcess.ServiceControllerStatus.Stopped)
22.    {
23.      Icon _stoppedIcon =
24.    GetIcon("OracleServiceControler.raddevoraserviceoff.ico");
25.      _notifyIcon.Icon = _stoppedIcon;
26. 
27.      _contextMenu.MenuItems[0].Enabled = false;
28.      _contextMenu.MenuItems[1].Enabled = true;
29.      _contextMenu.MenuItems[2].Enabled = false;
30.      _contextMenu.MenuItems[3].Enabled = true;
31.      _contextMenu.MenuItems[4].Enabled = true;
32.    }
33.  }
34.  catch (Exception ex)
35.  {
36.    MessageBox.Show(ex.Message.ToString(), "Oracle Service Controller",
37.      MessageBoxButtons.OK, MessageBoxIcon.Error);
38.  }
39.}

Stopping and Starting the Service

To stop the service take a look at the code below. The three steps I am taking are:

  1. Determine if the service is running.
  2. Determine if the service can be stopped.
  3. Stop the service.

01.private void StopService(object sender, EventArgs e)
02.{
03.  try
04.  {
05.    if (_oracleDatabaseServiceController.Status ==
06.        System.ServiceProcess.ServiceControllerStatus.Running)
07.    {
08.      if (_oracleDatabaseServiceController.CanStop == true)
09.      {
10.        _oracleDatabaseServiceController.Stop();
11.      }
12.    }
13.  }
14.  catch (Exception ex)
15.  {
16.    MessageBox.Show(ex.Message.ToString(), "Oracle Service Controller",
17.      MessageBoxButtons.OK, MessageBoxIcon.Error);
18.  }
19.}

To start the service take a look at the code below. Starting the service is very similar to stopping the service. The three steps I am taking are:

  1. Determine if the service is stopped.
  2. Start the service.

01.private void StartService(object sender, EventArgs e)
02.{
03.  try
04.  {
05.    if (_oracleDatabaseServiceController.Status ==
06.        System.ServiceProcess.ServiceControllerStatus.Stopped)
07.    {
08.      _oracleDatabaseServiceController.Start();
09.    }
10.  }
11.  catch (Exception ex)
12.  {
13.    MessageBox.Show(ex.Message.ToString(), "Oracle Service Controller",
14.      MessageBoxButtons.OK, MessageBoxIcon.Error);
15.  }
16.}

Exiting the Application

When it is time to exit the application it is very important to clean up the resources that we were using. As you can see I am performing actions such as stopping the timer and disposing of the objects I had created. Once again this is an important step as you should always clean up behind yourself. Do you not recall your mother always yelling at you to clean up?


01.private void ExitController(object sender, EventArgs e)
02.{
03.  try
04.  {
05.    _timer.Stop();
06.    _timer.Dispose();
07.    _notifyIcon.Visible = false;
08.    _notifyIcon.Dispose();
09.    _oracleDatabaseServiceController.Dispose();
10.    Application.Exit();
11.  }
12.  catch (Exception ex)
13.  {
14.    MessageBox.Show(ex.Message.ToString(), "Oracle Service Controller",
15.      MessageBoxButtons.OK, MessageBoxIcon.Error);
16.  }
17.}

Summary

Once you have compiled your project and run the executable you should notice a new icon in your system tray.

We have accomplished all of this with very little effort as A Windows Application and I hope that I have provided the groundwork for you to create your own application or expand upon this example. For example, in my source code which you can  at Radical Development I have incorporated an about form.






Sponsored Ads



Interview Questions
HR Interview Questions
Testing Interview Questions
SAP Interview Questions
Business Intelligence Interview Questions
Call Center Interview Questions

Databases

Clipper Interview Questions
DBA Interview Questions
Firebird Interview Questions
Hierarchical Interview Questions
Informix Interview Questions
Microsoft Access Interview Questions
MS SqlServer Interview Questions
MYSQL Interview Questions
Network Interview Questions
Object Relational Interview Questions
PL/SQL Interview Questions
PostgreSQL Interview Questions
Progress Interview Questions
Relational Interview Questions
SQL Interview Questions
SQL Server Interview Questions
Stored Procedures Interview Questions
Sybase Interview Questions
Teradata Interview Questions

Microsof Technologies

.Net Database Interview Questions
.Net Deployement Interview Questions
ADO.NET Interview Questions
ADO.NET 2.0 Interview Questions
Architecture Interview Questions
ASP Interview Questions
ASP.NET Interview Questions
ASP.NET 2.0 Interview Questions
C# Interview Questions
Csharp Interview Questions
DataGrid Interview Questions
DotNet Interview Questions
Microsoft Basics Interview Questions
Microsoft.NET Interview Questions
Microsoft.NET 2.0 Interview Questions
Share Point Interview Questions
Silverlight Interview Questions
VB.NET Interview Questions
VC++ Interview Questions
Visual Basic Interview Questions

Java / J2EE

Applet Interview Questions
Core Java Interview Questions
Eclipse Interview Questions
EJB Interview Questions
Hibernate Interview Questions
J2ME Interview Questions
J2SE Interview Questions
Java Interview Questions
Java Beans Interview Questions
Java Patterns Interview Questions
Java Security Interview Questions
Java Swing Interview Questions
JBOSS Interview Questions
JDBC Interview Questions
JMS Interview Questions
JSF Interview Questions
JSP Interview Questions
RMI Interview Questions
Servlet Interview Questions
Socket Programming Interview Questions
Springs Interview Questions
Struts Interview Questions
Web Sphere Interview Questions

Programming Languages

C Interview Questions
C++ Interview Questions
CGI Interview Questions
Delphi Interview Questions
Fortran Interview Questions
ILU Interview Questions
LISP Interview Questions
Pascal Interview Questions
Perl Interview Questions
PHP Interview Questions
Ruby Interview Questions
Signature Interview Questions
UML Interview Questions
VBA Interview Questions
Windows Interview Questions
Mainframe Interview Questions


Copyright © 2001-2025 Vyoms.com. All Rights Reserved. Home | About Us | Advertise With Vyoms.com | Jobs | Contact Us | Feedback | Link to Us | Privacy Policy | Terms & Conditions
Placement Papers | Get Your Free Website | IAS Preparation | C++ Interview Questions | C Interview Questions | Report a Bug | Romantic Shayari | CAT 2025

Fresher Jobs | Experienced Jobs | Government Jobs | Walkin Jobs | Company Profiles | Interview Questions | Placement Papers | Companies In India | Consultants In India | Colleges In India | Exams In India | Latest Results | Notifications In India | Call Centers In India | Training Institutes In India | Job Communities In India | Courses In India | Jobs by Keyskills | Jobs by Functional Areas

Testing Articles | Testing Books | Testing Certifications | Testing FAQs | Testing Downloads | Testing Interview Questions | Testing Jobs | Testing Training Institutes

Gate Articles | Gate Books | Gate Colleges | Gate Downloads | Gate Faqs | Gate Jobs | Gate News | Gate Sample Papers | Gate Training Institutes

MBA Articles | MBA Books | MBA Case Studies | MBA Business Schools | MBA Current Affairs | MBA Downloads | MBA Events | MBA Notifications | MBA FAQs | MBA Jobs
MBA Job Consultants | MBA News | MBA Results | MBA Courses | MBA Sample Papers | MBA Interview Questions | MBA Training Institutes

GRE Articles | GRE Books | GRE Colleges | GRE Downloads | GRE Events | GRE FAQs | GRE News | GRE Training Institutes | GRE Sample Papers

IAS Articles | IAS Books | IAS Current Affairs | IAS Downloads | IAS Events | IAS FAQs | IAS News | IAS Notifications | IAS UPSC Jobs | IAS Previous Question Papers
IAS Results | IAS Sample Papers | IAS Interview Questions | IAS Training Institutes | IAS Toppers Interview

SAP Articles | SAP Books | SAP Certifications | SAP Companies | SAP Study Materials | SAP Events | SAP FAQs | SAP Jobs | SAP Job Consultants
SAP Links | SAP News | SAP Sample Papers | SAP Interview Questions | SAP Training Institutes |


Copyright ©2001-2025 Vyoms.com, All Rights Reserved.
Disclaimer: VYOMS.com has taken all reasonable steps to ensure that information on this site is authentic. Applicants are advised to research bonafides of advertisers independently. VYOMS.com shall not have any responsibility in this regard.