}           //	end Terminate

        public int Prepare(DemoCreator aMyCreator)
        {
            Application.Instance.EnableTracing(
                EnumTraceGroup.ALL,
                EnumTraceGroup.ALL,
                EnumTraceGroup.ALL,
                EnumTraceGroup.ALL,
                "Trace.txt",
                10000000,
                0);

            int result = Application.Instance.Initialize(aMyCreator);

            return(result);
        }           //	end Prepare
        public int BuildAEAddressSpace()
        {
            int result = (int)EnumResultCode.S_OK;

            //AE
            DemoCreator        creator = (DemoCreator)Application.Instance.Creator;
            AeAddressSpaceRoot aeRoot  = Application.Instance.AeAddressSpaceRoot;

            AeAddressSpaceElement keyboardElement = creator.CreateDemoAeAddressSpaceElement();

            keyboardElement.Name        = "keyboard";
            keyboardElement.HasChildren = false;
            if (!aeRoot.AddChild(keyboardElement))
            {
                return((int)EnumResultCode.E_FAIL);
            }

            AeAddressSpaceElement mouseElement = creator.CreateDemoAeAddressSpaceElement();

            mouseElement.Name        = "mouse";
            mouseElement.HasChildren = true;
            if (!aeRoot.AddChild(mouseElement))
            {
                return((int)EnumResultCode.E_FAIL);
            }

            AeAddressSpaceElement rightButtonElement = creator.CreateDemoAeAddressSpaceElement();

            rightButtonElement.Name        = "right button";
            rightButtonElement.HasChildren = false;
            if (!mouseElement.AddChild(rightButtonElement))
            {
                return((int)EnumResultCode.E_FAIL);
            }

            AeAddressSpaceElement leftButtonElement = creator.CreateDemoAeAddressSpaceElement();

            leftButtonElement.Name        = "left button";
            leftButtonElement.HasChildren = false;
            if (!mouseElement.AddChild(leftButtonElement))
            {
                return((int)EnumResultCode.E_FAIL);
            }

            AeAddressSpaceElement timeElement = creator.CreateDemoAeAddressSpaceElement();

            timeElement.Name        = "time";
            timeElement.HasChildren = true;
            if (!aeRoot.AddChild(timeElement))
            {
                return((int)EnumResultCode.E_FAIL);
            }

            AeAddressSpaceElement localElement = creator.CreateDemoAeAddressSpaceElement();

            localElement.Name        = "local";
            localElement.HasChildren = true;
            if (!timeElement.AddChild(localElement))
            {
                return((int)EnumResultCode.E_FAIL);
            }

            AeAddressSpaceElement secondElement = creator.CreateDemoAeAddressSpaceElement();

            secondElement.Name        = "second";
            secondElement.HasChildren = false;
            if (!localElement.AddChild(secondElement))
            {
                return((int)EnumResultCode.E_FAIL);
            }

            AeAddressSpaceElement minuteElement = creator.CreateDemoAeAddressSpaceElement();

            minuteElement.Name        = "minute";
            minuteElement.HasChildren = false;
            if (!localElement.AddChild(minuteElement))
            {
                return((int)EnumResultCode.E_FAIL);
            }

            return(result);
        }
        }           //	end ProcessCommandLine

        public int BuildDAAddressSpace()
        {
            try
            {
                DemoCreator               creator             = (DemoCreator)Application.Instance.Creator;
                DaAddressSpaceRoot        daRoot              = Application.Instance.DaAddressSpaceRoot;
                DemoDaAddressSpaceElement allDataTypesElement = creator.CreateBasicElement("all data types");
                allDataTypesElement.HasChildren = true;
                if (!daRoot.AddChild(allDataTypesElement))
                {
                    return((int)EnumResultCode.E_FAIL);
                }
                DemoDaAddressSpaceElement dynamicElements = creator.CreateBasicElement("dynamic");
                dynamicElements.HasChildren = true;
                if (!allDataTypesElement.AddChild(dynamicElements))
                {
                    return((int)EnumResultCode.E_FAIL);
                }
                #region Child Variables for dynamic
                DemoDaAddressSpaceElement tag = null;
                tag = creator.CreateBasicDynamicElement(typeof(System.Byte));
                if (!dynamicElements.AddChild(tag))
                {
                    return((int)EnumResultCode.E_FAIL);
                }
                tag.Init();
                m_elemetList.Add(tag);
                tag = creator.CreateBasicDynamicElement(typeof(System.SByte));
                if (!dynamicElements.AddChild(tag))
                {
                    return((int)EnumResultCode.E_FAIL);
                }
                tag.Init();
                m_elemetList.Add(tag);
                tag = creator.CreateBasicDynamicElement(typeof(System.Int16));
                if (!dynamicElements.AddChild(tag))
                {
                    return((int)EnumResultCode.E_FAIL);
                }
                tag.Init();
                m_elemetList.Add(tag);
                tag = creator.CreateBasicDynamicElement(typeof(System.UInt16));
                if (!dynamicElements.AddChild(tag))
                {
                    return((int)EnumResultCode.E_FAIL);
                }
                tag.Init();
                m_elemetList.Add(tag);
                tag = creator.CreateBasicDynamicElement(typeof(System.Int32));
                if (!dynamicElements.AddChild(tag))
                {
                    return((int)EnumResultCode.E_FAIL);
                }
                tag.Init();
                m_elemetList.Add(tag);
                tag = creator.CreateBasicDynamicElement(typeof(System.UInt32));
                if (!dynamicElements.AddChild(tag))
                {
                    return((int)EnumResultCode.E_FAIL);
                }
                tag.Init();
                m_elemetList.Add(tag);
                tag = creator.CreateBasicDynamicElement(typeof(System.Int64));
                if (!dynamicElements.AddChild(tag))
                {
                    return((int)EnumResultCode.E_FAIL);
                }
                tag.Init();
                m_elemetList.Add(tag);
                tag = creator.CreateBasicDynamicElement(typeof(System.UInt64));
                if (!dynamicElements.AddChild(tag))
                {
                    return((int)EnumResultCode.E_FAIL);
                }
                tag.Init();
                m_elemetList.Add(tag);
                tag = creator.CreateBasicDynamicElement(typeof(System.Double));
                if (!dynamicElements.AddChild(tag))
                {
                    return((int)EnumResultCode.E_FAIL);
                }
                tag.Init();
                m_elemetList.Add(tag);
                tag = creator.CreateBasicDynamicElement(typeof(System.Boolean));
                if (!dynamicElements.AddChild(tag))
                {
                    return((int)EnumResultCode.E_FAIL);
                }
                tag.Init();
                m_elemetList.Add(tag);
                tag = creator.CreateBasicDynamicElement(typeof(System.String));
                if (!dynamicElements.AddChild(tag))
                {
                    return((int)EnumResultCode.E_FAIL);
                }
                tag.Init();
                m_elemetList.Add(tag);
                tag = creator.CreateBasicDynamicElement(typeof(System.DateTime));
                if (!dynamicElements.AddChild(tag))
                {
                    return((int)EnumResultCode.E_FAIL);
                }
                tag.Init();
                m_elemetList.Add(tag);
                tag = creator.CreateBasicDynamicElement(typeof(System.Byte[]));
                if (!dynamicElements.AddChild(tag))
                {
                    return((int)EnumResultCode.E_FAIL);
                }
                tag.Init();
                m_elemetList.Add(tag);
                tag = creator.CreateBasicDynamicElement(typeof(System.SByte[]));
                if (!dynamicElements.AddChild(tag))
                {
                    return((int)EnumResultCode.E_FAIL);
                }
                tag.Init();
                m_elemetList.Add(tag);
                tag = creator.CreateBasicDynamicElement(typeof(System.Int16[]));
                if (!dynamicElements.AddChild(tag))
                {
                    return((int)EnumResultCode.E_FAIL);
                }
                tag.Init();
                m_elemetList.Add(tag);
                tag = creator.CreateBasicDynamicElement(typeof(System.UInt16[]));
                if (!dynamicElements.AddChild(tag))
                {
                    return((int)EnumResultCode.E_FAIL);
                }
                tag.Init();
                m_elemetList.Add(tag);
                tag = creator.CreateBasicDynamicElement(typeof(System.Int32[]));
                if (!dynamicElements.AddChild(tag))
                {
                    return((int)EnumResultCode.E_FAIL);
                }
                tag.Init();
                m_elemetList.Add(tag);
                tag = creator.CreateBasicDynamicElement(typeof(System.UInt32[]));
                if (!dynamicElements.AddChild(tag))
                {
                    return((int)EnumResultCode.E_FAIL);
                }
                tag.Init();
                m_elemetList.Add(tag);
                tag = creator.CreateBasicDynamicElement(typeof(System.Double[]));
                if (!dynamicElements.AddChild(tag))
                {
                    return((int)EnumResultCode.E_FAIL);
                }
                tag.Init();
                m_elemetList.Add(tag);
                tag = creator.CreateBasicDynamicElement(typeof(System.Boolean[]));
                if (!dynamicElements.AddChild(tag))
                {
                    return((int)EnumResultCode.E_FAIL);
                }
                tag.Init();
                m_elemetList.Add(tag);
                tag = creator.CreateBasicDynamicElement(typeof(System.String[]));
                if (!dynamicElements.AddChild(tag))
                {
                    return((int)EnumResultCode.E_FAIL);
                }
                tag.Init();
                m_elemetList.Add(tag);
                tag = creator.CreateBasicDynamicElement(typeof(System.DateTime[]));
                if (!dynamicElements.AddChild(tag))
                {
                    return((int)EnumResultCode.E_FAIL);
                }
                tag.Init();
                m_elemetList.Add(tag);
                #endregion
                DemoDaAddressSpaceElement staticElements = creator.CreateBasicElement("static");
                staticElements.HasChildren = true;
                if (!allDataTypesElement.AddChild(staticElements))
                {
                    return((int)EnumResultCode.E_FAIL);
                }
                #region Child Variables for static
                tag = creator.CreateBasicStaticElement(typeof(System.Byte));
                if (!staticElements.AddChild(tag))
                {
                    return((int)EnumResultCode.E_FAIL);
                }
                tag.Init();
                tag = creator.CreateBasicStaticElement(typeof(System.SByte));
                if (!staticElements.AddChild(tag))
                {
                    return((int)EnumResultCode.E_FAIL);
                }
                tag.Init();
                tag = creator.CreateBasicStaticElement(typeof(System.Int16));
                if (!staticElements.AddChild(tag))
                {
                    return((int)EnumResultCode.E_FAIL);
                }
                tag.Init();
                tag = creator.CreateBasicStaticElement(typeof(System.UInt16));
                if (!staticElements.AddChild(tag))
                {
                    return((int)EnumResultCode.E_FAIL);
                }
                tag.Init();
                tag = creator.CreateBasicStaticElement(typeof(System.Int32));
                if (!staticElements.AddChild(tag))
                {
                    return((int)EnumResultCode.E_FAIL);
                }
                tag.Init();
                tag = creator.CreateBasicStaticElement(typeof(System.UInt32));
                if (!staticElements.AddChild(tag))
                {
                    return((int)EnumResultCode.E_FAIL);
                }
                tag.Init();
                tag = creator.CreateBasicStaticElement(typeof(System.Int64));
                if (!staticElements.AddChild(tag))
                {
                    return((int)EnumResultCode.E_FAIL);
                }
                tag.Init();
                tag = creator.CreateBasicStaticElement(typeof(System.UInt64));
                if (!staticElements.AddChild(tag))
                {
                    return((int)EnumResultCode.E_FAIL);
                }
                tag.Init();
                tag = creator.CreateBasicStaticElement(typeof(System.Double));
                if (!staticElements.AddChild(tag))
                {
                    return((int)EnumResultCode.E_FAIL);
                }
                tag.Init();
                tag = creator.CreateBasicStaticElement(typeof(System.Boolean));
                if (!staticElements.AddChild(tag))
                {
                    return((int)EnumResultCode.E_FAIL);
                }
                tag.Init();
                tag = creator.CreateBasicStaticElement(typeof(System.String));
                if (!staticElements.AddChild(tag))
                {
                    return((int)EnumResultCode.E_FAIL);
                }
                tag.Init();
                tag = creator.CreateBasicStaticElement(typeof(System.DateTime));
                if (!staticElements.AddChild(tag))
                {
                    return((int)EnumResultCode.E_FAIL);
                }
                tag.Init();
                tag = creator.CreateBasicStaticElement(typeof(System.Byte[]));
                if (!staticElements.AddChild(tag))
                {
                    return((int)EnumResultCode.E_FAIL);
                }
                tag.Init();
                tag = creator.CreateBasicStaticElement(typeof(System.SByte[]));
                if (!staticElements.AddChild(tag))
                {
                    return((int)EnumResultCode.E_FAIL);
                }
                tag.Init();
                tag = creator.CreateBasicStaticElement(typeof(System.Int16[]));
                if (!staticElements.AddChild(tag))
                {
                    return((int)EnumResultCode.E_FAIL);
                }
                tag.Init();
                tag = creator.CreateBasicStaticElement(typeof(System.UInt16[]));
                if (!staticElements.AddChild(tag))
                {
                    return((int)EnumResultCode.E_FAIL);
                }
                tag.Init();
                tag = creator.CreateBasicStaticElement(typeof(System.Int32[]));
                if (!staticElements.AddChild(tag))
                {
                    return((int)EnumResultCode.E_FAIL);
                }
                tag.Init();
                tag = creator.CreateBasicStaticElement(typeof(System.UInt32[]));
                if (!staticElements.AddChild(tag))
                {
                    return((int)EnumResultCode.E_FAIL);
                }
                tag.Init();
                tag = creator.CreateBasicStaticElement(typeof(System.Double[]));
                if (!staticElements.AddChild(tag))
                {
                    return((int)EnumResultCode.E_FAIL);
                }
                tag.Init();
                tag = creator.CreateBasicStaticElement(typeof(System.Boolean[]));
                if (!staticElements.AddChild(tag))
                {
                    return((int)EnumResultCode.E_FAIL);
                }
                tag.Init();
                tag = creator.CreateBasicStaticElement(typeof(System.String[]));
                if (!staticElements.AddChild(tag))
                {
                    return((int)EnumResultCode.E_FAIL);
                }
                tag.Init();
                tag = creator.CreateBasicStaticElement(typeof(System.DateTime[]));
                if (!staticElements.AddChild(tag))
                {
                    return((int)EnumResultCode.E_FAIL);
                }
                tag.Init();
                #endregion
                DemoDaAddressSpaceElement functionElement = creator.CreateBasicElement("function");
                functionElement.HasChildren = true;
                if (!daRoot.AddChild(functionElement))
                {
                    return((int)EnumResultCode.E_FAIL);
                }
                DemoDaAddressSpaceElement sinElement = creator.CreateSinusElement();
                if (!functionElement.AddChild(sinElement))
                {
                    return((int)EnumResultCode.E_FAIL);
                }
                sinElement.Init();
                m_elemetList.Add(sinElement);
                DemoDaAddressSpaceElement cosElement = creator.CreateCosinusElement();
                if (!functionElement.AddChild(cosElement))
                {
                    return((int)EnumResultCode.E_FAIL);
                }
                cosElement.Init();
                m_elemetList.Add(cosElement);
                DemoDaAddressSpaceElement tanElement = creator.CreateTanElement();
                if (!functionElement.AddChild(tanElement))
                {
                    return((int)EnumResultCode.E_FAIL);
                }
                tanElement.Init();
                m_elemetList.Add(tanElement);
                DemoDaAddressSpaceElement simulationElement = creator.CreateSimulationElement();
                if (!functionElement.AddChild(simulationElement))
                {
                    return((int)EnumResultCode.E_FAIL);
                }
                simulationElement.Init();
                DemoDaAddressSpaceElement sleepIntervalElement = creator.CreateSleepIntervalElement();
                if (!functionElement.AddChild(sleepIntervalElement))
                {
                    return((int)EnumResultCode.E_FAIL);
                }
                sleepIntervalElement.Init();
                DemoDaAddressSpaceElement timeElement = creator.CreateBasicElement("time");
                timeElement.HasChildren = true;
                if (!daRoot.AddChild(timeElement))
                {
                    return((int)EnumResultCode.E_FAIL);
                }
                DemoDaAddressSpaceElement dateElement = creator.CreateTimeElement("date",
                                                                                  TimeVariable.TimeType.type_date,
                                                                                  TimeVariable.TimeZone.zone_local);
                if (!timeElement.AddChild(dateElement))
                {
                    return((int)EnumResultCode.E_FAIL);
                }
                DemoDaAddressSpaceElement localElement = creator.CreateBasicElement("local");
                localElement.HasChildren = true;
                if (!timeElement.AddChild(localElement))
                {
                    return((int)EnumResultCode.E_FAIL);
                }
                DemoDaAddressSpaceElement localHour = creator.CreateTimeElement("hour",
                                                                                TimeVariable.TimeType.type_hour,
                                                                                TimeVariable.TimeZone.zone_local);
                if (!localElement.AddChild(localHour))
                {
                    return((int)EnumResultCode.E_FAIL);
                }
                DemoDaAddressSpaceElement localMinute = creator.CreateTimeElement("minute",
                                                                                  TimeVariable.TimeType.type_minute,
                                                                                  TimeVariable.TimeZone.zone_local);
                if (!localElement.AddChild(localMinute))
                {
                    return((int)EnumResultCode.E_FAIL);
                }
                DemoDaAddressSpaceElement localSecond = creator.CreateTimeElement("second",
                                                                                  TimeVariable.TimeType.type_second,
                                                                                  TimeVariable.TimeZone.zone_local);
                if (!localElement.AddChild(localSecond))
                {
                    return((int)EnumResultCode.E_FAIL);
                }
                DemoDaAddressSpaceElement localString = creator.CreateTimeElement("string",
                                                                                  TimeVariable.TimeType.type_string,
                                                                                  TimeVariable.TimeZone.zone_local);
                if (!localElement.AddChild(localString))
                {
                    return((int)EnumResultCode.E_FAIL);
                }
                DemoDaAddressSpaceElement localArray = creator.CreateTimeElement("array",
                                                                                 TimeVariable.TimeType.type_array,
                                                                                 TimeVariable.TimeZone.zone_local);
                if (!localElement.AddChild(localArray))
                {
                    return((int)EnumResultCode.E_FAIL);
                }
                DemoDaAddressSpaceElement gmtElement = creator.CreateBasicElement("GMT");
                gmtElement.HasChildren = true;
                if (!timeElement.AddChild(gmtElement))
                {
                    return((int)EnumResultCode.E_FAIL);
                }
                DemoDaAddressSpaceElement gmtHour = creator.CreateTimeElement("hour",
                                                                              TimeVariable.TimeType.type_hour,
                                                                              TimeVariable.TimeZone.zone_GMT);
                if (!gmtElement.AddChild(gmtHour))
                {
                    return((int)EnumResultCode.E_FAIL);
                }
                DemoDaAddressSpaceElement gmtMinute = creator.CreateTimeElement("minute",
                                                                                TimeVariable.TimeType.type_minute,
                                                                                TimeVariable.TimeZone.zone_GMT);
                if (!gmtElement.AddChild(gmtMinute))
                {
                    return((int)EnumResultCode.E_FAIL);
                }
                DemoDaAddressSpaceElement gmtSecond = creator.CreateTimeElement("second",
                                                                                TimeVariable.TimeType.type_second,
                                                                                TimeVariable.TimeZone.zone_GMT);
                if (!gmtElement.AddChild(gmtSecond))
                {
                    return((int)EnumResultCode.E_FAIL);
                }
                DemoDaAddressSpaceElement gmtString = creator.CreateTimeElement("string",
                                                                                TimeVariable.TimeType.type_string,
                                                                                TimeVariable.TimeZone.zone_GMT);
                if (!gmtElement.AddChild(gmtString))
                {
                    return((int)EnumResultCode.E_FAIL);
                }
                DemoDaAddressSpaceElement gmtArray = creator.CreateTimeElement("array",
                                                                               TimeVariable.TimeType.type_array,
                                                                               TimeVariable.TimeZone.zone_GMT);
                if (!gmtElement.AddChild(gmtArray))
                {
                    return((int)EnumResultCode.E_FAIL);
                }
                DemoDaAddressSpaceElement timeSlotElement = creator.CreateBasicElement("time slot");
                timeSlotElement.HasChildren = true;
                if (!timeElement.AddChild(timeSlotElement))
                {
                    return((int)EnumResultCode.E_FAIL);
                }
                DemoDaAddressSpaceElement timeSlot1 = creator.CreateBasicElement("slot 1");
                timeSlot1.HasChildren = true;
                if (!timeSlotElement.AddChild(timeSlot1))
                {
                    return((int)EnumResultCode.E_FAIL);
                }
                DemoDaAddressSpaceElement slot1Start = creator.CreateTimeElement("start",
                                                                                 TimeVariable.TimeType.type_limitSecond,
                                                                                 TimeVariable.TimeZone.zone_none);
                if (!timeSlot1.AddChild(slot1Start))
                {
                    return((int)EnumResultCode.E_FAIL);
                }
                DemoDaAddressSpaceElement slot1End = creator.CreateTimeElement("end",
                                                                               TimeVariable.TimeType.type_limitSecond,
                                                                               TimeVariable.TimeZone.zone_none);
                if (!timeSlot1.AddChild(slot1End))
                {
                    return((int)EnumResultCode.E_FAIL);
                }
                DemoDaAddressSpaceElement timeSlot2 = creator.CreateBasicElement("slot 2");
                timeSlot2.HasChildren = true;
                if (!timeSlotElement.AddChild(timeSlot2))
                {
                    return((int)EnumResultCode.E_FAIL);
                }
                DemoDaAddressSpaceElement slot2Start = creator.CreateTimeElement("start",
                                                                                 TimeVariable.TimeType.type_limitSecond,
                                                                                 TimeVariable.TimeZone.zone_none);
                if (!timeSlot2.AddChild(slot2Start))
                {
                    return((int)EnumResultCode.E_FAIL);
                }
                DemoDaAddressSpaceElement slot2End = creator.CreateTimeElement("end",
                                                                               TimeVariable.TimeType.type_limitSecond,
                                                                               TimeVariable.TimeZone.zone_none);
                if (!timeSlot2.AddChild(slot2End))
                {
                    return((int)EnumResultCode.E_FAIL);
                }
                DemoDaAddressSpaceElement alarmSimulationElement = creator.CreateBasicElement("alarm simulation");
                alarmSimulationElement.HasChildren = true;
                if (!daRoot.AddChild(alarmSimulationElement))
                {
                    return((int)EnumResultCode.E_FAIL);
                }
                DemoDaAddressSpaceElement fireSimpleEvent = creator.CreateAlarmSimulationElement("fire simple event",
                                                                                                 AlarmSimulation.AlarmType.simple);
                if (!alarmSimulationElement.AddChild(fireSimpleEvent))
                {
                    return((int)EnumResultCode.E_FAIL);
                }
                fireSimpleEvent.Init();
                DemoDaAddressSpaceElement fireTrackingEvent = creator.CreateAlarmSimulationElement("fire tracking event",
                                                                                                   AlarmSimulation.AlarmType.tracking);
                if (!alarmSimulationElement.AddChild(fireTrackingEvent))
                {
                    return((int)EnumResultCode.E_FAIL);
                }
                fireTrackingEvent.Init();
                DemoDaAddressSpaceElement keyboardElement = creator.CreateBasicElement("keyboard");
                keyboardElement.HasChildren = true;
                if (!daRoot.AddChild(keyboardElement))
                {
                    return((int)EnumResultCode.E_FAIL);
                }
                m_keyElement = creator.CreateKeyElement();
                if (!keyboardElement.AddChild(m_keyElement))
                {
                    return((int)EnumResultCode.E_FAIL);
                }
                m_keyElement.Init();
            }
            catch (Exception exc)
            {
                Trace(
                    EnumTraceLevel.ERR,
                    EnumTraceGroup.USER1,
                    "OpcServer:;BuildAddressSpace",
                    exc.ToString());
                return((int)EnumResultCode.E_FAIL);
            }               //	end try...catch

            return((int)EnumResultCode.S_OK);
        }
        }           //  end StartAESimulationThread

        //--
        #endregion

        public static void Main(String[] args)
        {
            try
            {
                int result = (int)EnumResultCode.S_OK;
                EndEvent = new AutoResetEvent(false);
                Console console = new Console();
                MyWin32.HandlerRoutine handlerRoutine = new MyWin32.HandlerRoutine(MyWin32.Handler);
                MyWin32.SetConsoleCtrlHandler(
                    handlerRoutine,
                    true);


                //	create and initialize the OpcServer instance
                console.CreateOpcServer();
                OpcServer server = console.OpcServer;
                server.Initialize();

                DemoCreator creator = new DemoCreator();
                if (!ResultCode.SUCCEEDED(server.Prepare(creator)))
                {
                    server.Terminate();
                    MyWin32.Handler(MyWin32.CtrlTypes.CTRL_CLOSE_EVENT);
                    server = null;
                    return;
                }                   //	end if

                //	handle the command line arguments (register/unregister, etc)
                string commandline = Environment.CommandLine;
                result = server.ProcessCommandLine(commandline);

                if (result != (uint)EnumResultCode.S_OK)
                {
                    if (result == (uint)EnumResultCode.S_FALSE)
                    {
                        //registration operation succesful
                        server.Trace(
                            EnumTraceLevel.INF,
                            EnumTraceGroup.USER1,
                            "Console::Main",
                            "Registration succeeded");
                    }
                    else
                    {
                        server.Trace(
                            EnumTraceLevel.INF,
                            EnumTraceGroup.USER1,
                            "Console::Main",
                            "Registration failed");
                    }                       //	end if...else

                    //	no matter what close the application if
                    //processCommandLine returned something different of S_OK
                    server.Terminate();
                    server = null;
                    return;
                }                   //	end if

                //	start the OPC server's I/O internal mechanism
                if (ResultCode.SUCCEEDED(server.Start()))
                {
                    //	build the namespace
                    server.BuildAddressSpace();
                    //	declare the namespaces built and the server ready for clients to connect
                    server.Ready();
                }                   //	end if
                else
                {
                    server.Trace(
                        EnumTraceLevel.WRN,
                        EnumTraceGroup.USER1,
                        "Console::Main",
                        "Serrver start failed");
                    return;
                }
                //	start the simulation thread
                if (ResultCode.SUCCEEDED(result))
                {
                    console.StartDASimulationThread();
                    console.StartAESimulationThread();
                }                   //	end if
                System.Console.WriteLine("Press Ctrl-C to exit");

                while (!Console.End)
                {
                    //	TODO: place your cyclic code here
                    Thread.Sleep(1000);
                }                   //	end while

                //	terminate the DA simulation
                console.SimulationDAEnd = true;
                console.MutexDA.WaitOne();
                console.MutexDA.ReleaseMutex();

                //	terminate the AE simulation
                console.SimulationAEEnd = true;
                console.MutexAE.WaitOne();
                console.MutexAE.ReleaseMutex();

                server.Stop();
                server.Terminate();
                server = null;
                MyWin32.Handler(MyWin32.CtrlTypes.CTRL_CLOSE_EVENT);
            }
            catch (Exception exc)
            {
                System.Console.WriteLine(exc.ToString());
            } //	end try...catch
        }     //	end Main