December 6, 2004 (Mon)

The Evolution of a Programmer

http://www.ariel.com.au/jokes/The_Evolution_of_a_Programmer.html

程序員的進化。有名程序「Hello World!」究竟該怎麼寫才算好呢,我們來看看吧。

Posted by KichikuMan at 22:43 | 引用
Comments

Microsoft 果然係簡單複雜化的箇中能手...一個 Hello World 變做 COM 可以係咁恐怖...
(o個個 Program 咁多個 Program 當中唯一一個睇唔明的...)

Posted by: 宗仔 at Dec 8, 07:38

//接棒~ .NET Service

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.ServiceProcess;

namespace HelloWorldService
{
public class Service1 : System.ServiceProcess.ServiceBase
{
private System.Diagnostics.EventLog eventLog1;
///
/// Required designer variable.
///
private System.ComponentModel.Container components = null;

public Service1()
{
// This call is required by the Windows.Forms Component Designer.
InitializeComponent();

// TODO: Add any initialization after the InitComponent call
if(!System.Diagnostics.EventLog.SourceExists("DoDyLogSourse"))
{
System.Diagnostics.EventLog.CreateEventSource("DoDyLogSourse","DoDyLog");
}

eventLog1.Source = "DoDyLogSourse";
eventLog1.Log ="DoDyLog";

}

// The main entry point for the process
static void Main()
{
System.ServiceProcess.ServiceBase[] ServicesToRun;

// More than one user Service may run within the same process. To add
// another service to this process, change the following line to
// create a second service object. For example,
//
// ServicesToRun = New System.ServiceProcess.ServiceBase[] {new Service1(), new MySecondUserService()};
//
ServicesToRun = new System.ServiceProcess.ServiceBase[] { new HelloWorldService.Service1()};

System.ServiceProcess.ServiceBase.Run(ServicesToRun);
}

///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent()
{
this.eventLog1 = new System.Diagnostics.EventLog();
((System.ComponentModel.ISupportInitialize)(this.eventLog1)).BeginInit();
//
// eventLog1
//
this.eventLog1.Log = "DoDyLog";
this.eventLog1.Source = "DoDyLogSource";
//
// Service1
//
this.ServiceName = "HelloWorldService";
((System.ComponentModel.ISupportInitialize)(this.eventLog1)).EndInit();

}

///
/// Clean up any resources being used.
///
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

///
/// Set things in motion so your service can do its work.
///
protected override void OnStart(string[] args)
{
// TODO: Add code here to start your service.
eventLog1.WriteEntry("Hello world! Service started");
}

///
/// Stop this service.
///
protected override void OnStop()
{
// TODO: Add code here to perform any tear-down necessary to stop your service.
eventLog1.WriteEntry("Hello world! Service stopped");
}
protected override void OnContinue()
{
eventLog1.WriteEntry("Hello world! Service continuing");
}
}
}

Posted by: kei at Dec 8, 15:42
Post a comment









Remember personal info?