Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
290 views
in Technique[技术] by (71.8m points)

c# - Working with Winforms UI while acquiring data

I develop Forms Application using C#. This App will collect data from a spectrometer device. When I set continuous acquisition, I am not able to perform other operations during the acquisition happens. I want to zoom the chart and also perform other operations while the acquisition happens. Now when I click zoom button it is only enabling after the acquisition is over. Kindly help me to solve this.

Please see part of code which has a button click to start acquisition. One chart is also getting updated with the values from spectrometer. Also screen shot of UI is at bottom.

 private void button2_Click(object sender, EventArgs e)
    {
        while (true)
        {
            this.Refresh();
            int numberOfPixels; // number of CCD elements
            double[] spectrum;
            spectrum = null;   // spectrometerIndex = 0;

            if (spectrometerIndex == -1)
                return; // no available spectrometer

            numberOfPixels = wrapper.getNumberOfPixels(spectrometerIndex);
            wrapper.setBoxcarWidth(spectrometerIndex, 0);
            wrapper.setCorrectForElectricalDark(spectrometerIndex, 1);
            wrapper.setIntegrationTime(spectrometerIndex, 1000); // acquisition time in microsecs

            int acquiretime = 100;
            if (textBoxin.Text != "")

            {
                int.TryParse(textBoxin.Text, out acquiretime); //arbitrary acquiretime

            }

            Stopwatch integrate = new Stopwatch();
            integrate.Start();
            while (integrate.Elapsed < TimeSpan.FromMilliseconds(acquiretime))
            {
                this.Refresh();
                spectrum = (double[])wrapper.getSpectrum(spectrometerIndex); data from spectrometer

            }

            integrate.Stop();
        }
    }

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.8k users

...