private void Initialize()
    {
        using (ManualResetEvent syncEvent = new ManualResetEvent())
        {
            ApiStateUpdateEventHandler handler = null;

            handler = delegate(string who, int howMuch)
            {
                bool cond1 = false;
                bool cond2 = false;

                if (who.Equals("Something") && howMuch == 1)
                {
                    cond1 = true;
                }
                else if (who.Equals("SomethingElse") && howMuch == 1)
                {
                    cond2 = true;
                }

                //wait for both conditions to be true

                if (!cond1 && !cond2)
                {
                    return;
                }

                this.apiObject.ApiStateUpdate -= handler;

                syncEvent.Set();
            };

            this.apiObject.ApiStateUpdate += handler;
            WaitWithDoEvents(syncEvent, Timeout.Infinite);
        }
    }
Пример #2
0
    public void Initialize()
    {
        ApiStateUpdateEventHandler handler = null;

        handler = delegate(string who, int howMuch)
        {
            var cond1 = false;
            var cond2 = false;

            if (who.Equals("Something") && howMuch == 1)
            {
                cond1 = true;
            }
            else if (who.Equals("SomethingElse") && howMuch == 1)
            {
                cond2 = true;
            }

            //wait for both conditions to be true

            if (!cond1 && !cond2)
            {
                return;
            }

            this.apiObject.ApiStateUpdate -= handler;

            // fire an event when both conditions are met
            if (this.Initialized != null)
            {
                this.Initialized(this, new EventArgs());
            }
        };

        this.apiObject.ApiStateUpdate += handler;
    }