1

我的 windows phone 7.1 项目中有一个滑块。操作时,此滑块会触发一个事件,该事件启动后台工作程序以执行多个三角运算。

如果我在滑块上移动光标,虽然我在操作启动事件中实现了后台工作程序 cancelAsync 方法,但我的响应会有一定的延迟,我想要更多的响应能力,我该如何实现?

代码:

   private void sliderCosinus_ManipulationStarted(object sender,ManipulationStartedEventArgs e)
    {
        if (bw.WorkerSupportsCancellation == true)
        {
            bw.CancelAsync();   // Cancel the asynchronous operation.
        }
    }

     private void sldCosinus_ManipulationCompleted(object sender, ManipulationCompletedEventArgs e)
    {
        try
        {
            Value = Convert.ToInt32(sldCosinus.Value) * 10;
        }
        catch
        {
             // errore message here
        }
        finally 
        {
        }
    }
     private void bw_DoWork(object sender, DoWorkEventArgs e)
    {
        BackgroundWorker worker = sender as BackgroundWorker;


            if ((worker.CancellationPending == true))
            {
                e.Cancel = true;
            }
            else
            {
                Dispatcher.BeginInvoke(() => app.IsEffectApplied=TrigonometricTrans()
    // TrigonomtriecTrans calculate sin and cosinus for every pixel in image 
            }
    }
    private void bw_ProgressChanged(object sender, ProgressChangedEventArgs e)
    {
        // progress bar here 
    }
    private void bw_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
    {
        if ((e.Cancelled == true))
        {
            //this.tbProgress.Text = "Canceled!";
        }
        else if (!(e.Error == null))
        {
            //this.tbProgress.Text = ("Error: " + e.Error.Message);
        }
        else
        {
           DoubleBufferToScreen();
        }
    }
4

0 回答 0