English 中文(简体)
在我的“数字上的变化”活动中,要求发挥职能,在方案运行缓慢时,改变数字价值时,这种作用就会减弱。
原标题:In my numericUpDown Changed event im calling a function() and when im changing the numeric value when program is running its getting slower
  • 时间:2011-11-24 10:08:47
  •  标签:
  • c#

这是经过数字改动的事件代码,其时间为2 个称道,即功能为DoThresholdCheck。

问题是,在这一职能中,每当改变数字价值时,每当改变数字价值时,清单就从一开始就设定。 问题是,如果在我方案中使用一个大档案,清单中有时包含16500个指数,而如果在改变数字价值时,它需要时间去除清单,这样一格猜。 如果使用较小的录像档案,例如包含4000个指数的清单,就不存在问题。 我试图使用时光2,即在每改变数字价值时,可以等到0.5秒钟,但是仍然不错。

当改变数字价值时,在大型录像档案中,它把价值改变为1-2秒钟! 页: 1

解决该问题的任何方式? 也许可以稍微读一下名单,即使名单是大的?

private void numericUpDown1_ValueChanged(object sender, EventArgs e)
        {
            Options_DB.Set_numericUpDownValue(numericUpDown1.Value);
            if (isNumericChanged == true)
            {
                isNumericChanged = false;
                myTrackPanelss1.trackBar1.Scroll -= new EventHandler(trackBar1_Scroll);
                DoThresholdCheck();
                counter = 0;
            }
        }

        private void timer2_Tick(object sender, EventArgs e)
        {
            counter++;
            if (counter > 1)
            {
                isNumericChanged = true;
                //timer2.Stop();
            }
        }

这是《清点功能法》:

private void DoThresholdCheck()
        {
            List<string> fts;
            //const string D6 = "000{0}.bmp";
            if (Directory.Exists(subDirectoryName))
            {



                if (!File.Exists(subDirectoryName + "\" + averagesListTextFile + ".txt"))
                {
                    return;
                }
                else
                {



                    bool trackbarTrueFalse = false ;

                        fts = new List<string>();
                        int counter = 0;
                        double thershold = (double)numericUpDown1.Value;
                        double max_min_threshold = (thershold / 100) * (max - min) + min;
                        //label13.Text = max_min_threshold.ToString();
                        _fi = new DirectoryInfo(subDirectoryName).GetFiles("*.bmp");


                        for (int i = 0; i < myNumbers.Count; i++)
                        {
                            if (myNumbers[i] >= max_min_threshold)
                            {
                                //f.Add(i);
                                string t = i.ToString("D6") + ".bmp";
                                if (File.Exists(subDirectoryName + "\" + t))
                                {
                                    counter++;
                                    button1.Enabled = false;
                                    myTrackPanelss1.trackBar1.Enabled = true;
                                    trackbarTrueFalse = true;
                                    label9.Visible = true;
                                   // myTrackPanelss1.trackBar1.Scroll += new EventHandler(trackBar1_Scroll);
                                    //myTrackPanelss1.trackBar1.Minimum = 0;
                                   // myTrackPanelss1.trackBar1.Maximum = f.Count;
                                   // myTrackPanelss1.trackBar1.Value = f.Count;
                                   // myFiles = new Bitmap(myTrackPanelss1.trackBar1.Value);



                                }
                                else
                                {
                                    label9.Visible = false;
                                    trackbarTrueFalse = false;
                                    button1.Enabled = true;
                                    myTrackPanelss1.trackBar1.Enabled = false;
                                    myTrackPanelss1.trackBar1.Value = 0;
                                    pictureBox1.Image = Properties.Resources.Weather_Michmoret;
                                    label5.Visible = true;
                                    secondPass = true;
                                    break;
                                }

                                //fts.Add(string.Format(D6, myNumbers[i]));
                            }
                        }

                        //myTrackPanelss1.trackBar1.Maximum = _fi.Length - 1;
                        if (myTrackPanelss1.trackBar1.Maximum > 0)
                        {
                            if (trackbarTrueFalse == false)
                            {
                                myTrackPanelss1.trackBar1.Value = 0;
                            }
                            else
                            {
                                myTrackPanelss1.trackBar1.Maximum = counter;
                                myTrackPanelss1.trackBar1.Value = 0;
                                SetPicture(0);
                                myTrackPanelss1.trackBar1.Scroll += new EventHandler(trackBar1_Scroll);
                            }
                            //checkBox2.Enabled = true;
                        }
                        if (_fi.Length >= 0)
                        {
                            label15.Text = _fi.Length.ToString();
                            label15.Visible = true;
                        }
}
            }
            else
            {
                button1.Enabled = true;
            }
}
问题回答

try to cache results from DoThresholdCheck method

如果实际需要处理,你可以mag忙地接手处理过程。 • 探索:

(1) 尽量减少处理工作——这是所有必要的吗? 您能够处理其中的任何问题,而且每次价值变化时只能补足一小部分?

2) Do the processing less often - do you have to recompute every single time?

3) 处理另一个问题——至少是贵方倡议的响应性,在背景任务完成后,你可以将结果交付给万国倡议。 然而,如果你在重新处理以前的价值变化时再次进行,那么这一模式将是一个相对复杂的变数。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签