Click here to Skip to main content
15,891,136 members
Articles / Web Development / Apache

The platform-independent code with Mono: Client-server application sample

Rate me:
Please Sign up or sign in to vote.
4.80/5 (23 votes)
24 Mar 2010CPOL10 min read 74K   798   59  
This article shows how we can develop the platform-independent software with Mono usage
using System;
using System.ComponentModel;
using System.Threading;
using System.ServiceProcess;

using InfoCenter.Agent.Helpers;

namespace InfoCenter.Agent
{
  public class AgentService : System.ServiceProcess.ServiceBase
  {
    private Container components;
    private Thread  listenerThread;
	private Listener listener;

		
    public AgentService()
    {
      Logger.Debug("Service ctor");
      try 
	{
				InitializeComponent();
				listener = new Listener();
				
      } catch (Exception e)
        {
          Logger.Fatal(e.Message);
        }
      Logger.Debug("Service ctor complete");
    } 

    // The main entry point for the process of service
    static void Main()
    {
      ServiceBase[] services;
     
      Logger.Debug("Service entry point");
      services = new ServiceBase[] { new AgentService() };
      ServiceBase.Run(services);
    } 
   
    private void InitializeComponent()
    {
      components = new System.ComponentModel.Container();
      this.ServiceName = "InfoCenter agent";
    } 
   
    protected override void OnStart(string[] args)
    {
      Logger.Debug("Service OnStart");
      
      //listener.Run = true;
      listenerThread = new Thread(new ThreadStart(listener.Start));
      listenerThread.Start();
      
    } 

    protected override void OnStop()
    {
      Logger.Debug("Service OnStop");
      
      listenerThread.Abort();
      listener = null;
      
    } 
   
    protected override void OnContinue()
    {
      Logger.Debug("Service OnContinue");;
    } 
   
    protected override void OnPause()
    {
      Logger.Debug("Service OnPause");
    } 
   
    protected override void OnShutdown()
    {
      Logger.Debug("Service OnShutdown");
    } 
  } 
} 

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

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


Written By
Software Developer (Senior) Nokia
Germany Germany
Interested in design/development of framework functionality using the best patterns and practices.

Comments and Discussions