Ejemplo n.º 1
0
        private void comboMode_SelectedIndexChanged(object sender, EventArgs e)
        {
            EModes newMode;

            try { newMode = (EModes)Enum.Parse(typeof(EModes), comboMode.SelectedItem.ToString()); }
            catch { return; }
            if (mMode == newMode)
            {
                return;
            }
            mMode = newMode;
            try
            {
                if (mWorker != null)
                {
                    mWorker.CancelAsync();
                    mWorker.Dispose();
                }
            }
            catch { }
            finally { mWorker = null; }

            panelParam.Controls.Clear();

            Effects.EffectBase effect = Effects.EffectBase.GetEffect(mMode);
            if (effect == null)
            {
                return;
            }

            effect.Dock = DockStyle.Fill;
            panelParam.Controls.Add(effect);

            previewPanel.Visible = effect.IsAnimation;
            if (effect.IsAnimation)
            {
                mWorker = new BackgroundWorker();
                mWorker.WorkerSupportsCancellation = true;
                mWorker.DoWork             += MWorker_DoWork;
                mWorker.RunWorkerCompleted += MWorker_RunWorkerCompleted;
                mWorker.RunWorkerAsync(new object[] { this, effect });
            }
            else
            {
                if (mCtrl != null)
                {
                    mCtrl.RequestMode(0, 0, 0);
                }
                Thread.Sleep(10);
                effect.Init(this);
                effect.Work(this);
            }
            Settings.Instance.Mode = mMode;
        }
Ejemplo n.º 2
0
        private void MWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            try
            {
                BackgroundWorker worker = sender as BackgroundWorker;
                if (worker == null)
                {
                    return;
                }

                if (!(e.Argument is object[]) || ((object[])e.Argument).Length != 2)
                {
                    return;
                }
                MainForm form = ((object[])e.Argument)[0] as MainForm;
                if (form == null)
                {
                    return;
                }

                Effects.EffectBase effect = ((object[])e.Argument)[1] as Effects.EffectBase;
                if (effect == null)
                {
                    return;
                }

                if (mCtrl != null)
                {
                    mCtrl.RequestMode(0, 0, 0);
                }

                effect.Init(this);

                while (true)
                {
                    if (worker.CancellationPending)
                    {
                        return;
                    }
                    effect.Work(this);
                }
            }
            catch { e.Cancel = true; }
        }