namespace OCDemoServerCS
{
// Default value for the Construction string specified here
[ConstructionEnabled(Default="Default Construction String")]
public class ObjectConstructionTest : ServicedComponent
{
public ObjectConstructionTest()
{
// Constructor called first on instance creation
MessageBox.Show("Constructor called", "Object Construction Sample");
}
protected override void Construct(string constructString)
{
// Construct method called next, after constructor
MessageBox.Show("IObjectConstruct method called with value \"" + constructString + "\"", "Object Construction Sample");
}
public void DoWork ()
{
MessageBox.Show("DoWork method called", "Object Construction Sample");
}
}
}
===================================================
using System;
using System.Drawing;
using System.Windows.Forms;
using System.ComponentModel;
using OCDemoServerCS;
public class OCForm: Form
{
private Button constructButton;
public OCForm()
{
InitializeComponent();
}
private void InitializeComponent()
{
this.constructButton = new Button ();
constructButton.Location = new System.Drawing.Point (80, 40);
constructButton.Size = new System.Drawing.Size (96, 24);
constructButton.TabIndex = 1;
constructButton.Text = "Create Object";
constructButton.Click += new EventHandler (this.Construct_Click);
this.FormBorderStyle = FormBorderStyle.FixedDialog;
this.Text = "Object Construction String Demo";
this.AutoScaleBaseSize = new Size (5, 13);
this.ClientSize = new System.Drawing.Size (270, 120);
this.Controls.Add (this.constructButton);
}
try
{
// The 'using' construct below results in a call to Dispose on exiting the
// curly braces. It could be replaced with an explicit call to Object.Dispose
// This is a C#-specific construct.
//
// It is important to dispose COM+ objects as soon as possible so that
// COM+ metadata such as context does not remain in memory unnecessarily
// and so that COM+ services such as Object Pooling work properly.
using(ObjectConstructionTest order = new ObjectConstructionTest())
{
order.DoWork();
}
}