c# - 在获取数据时使用 Winforms UI
问题描述
我使用 C# 开发表单应用程序。此应用程序将从光谱仪设备收集数据。当我设置连续采集时,在采集过程中我无法执行其他操作。我想在采集发生时缩放图表并执行其他操作。现在,当我单击缩放按钮时,它仅在采集结束后启用。请帮我解决这个问题。
请查看部分代码,其中包含单击以开始获取的按钮。一张图表也正在使用光谱仪的值进行更新。UI的屏幕截图也在底部。
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();
}
}
解决方案
推荐阅读
- json - 无法从反应表单将数据发布到我的 API
- matplotlib - matplotib 3D 图形显示表面和轮廓以及正确隐藏的部分?
- r - 闪亮的应用程序在本地运行没有问题,但被服务器断开连接
- javascript - 如何将坐标保存到 Firebase
- docker - 为什么我无法连接到 docker 中的 postgres?
- kotlin - 期待 Kotlin 1.3 的顶级声明
- c++ - 如何解决 macOS catalina 上的此错误?
- r - 删除变量的一个值出现一次的 ID
- rust - 在字符串字符 for 循环中使用可变或不可变引用
- amazon-web-services - 您是否需要为访问 AWS Cost Explorer 控制面板付费?