求助大神,在C#编程出现如下情况,请问该如何处理?
using System;
using System.Collections.Generic;
using
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using NationalInstruments;
using NationalInstruments.DAQmx;
namespace DAQ_Example
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
CheckForIllegalCrossThreadCalls = false;
}
System.Timers.Timer timer2;
private void button1_Click(object sender, EventArgs e)
{
timer2 = new System.Timers.Timer(100);
timer2.AutoReset = true;
timer2.Enabled = true;
timer2.Elapsed += new System.Timers.ElapsedEventHandler(timer2_Elapsed);
}
void timer2_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
// Control.CheckForIllegalCrossThreadCalls = false;
Task temperatureTask = new Task();
AIChannel myAIChannel;
myAIChannel = temperatureTask.AIChannels.CreateThermocoupleChannel(
"Dev1/ai0",
"Temperature",
0,
100,
AIThermocoupleType.J,
AITemperatureUnits.DegreesC,
25
);
AnalogSingleChannelReader reader = new
AnalogSingleChannelReader(temperatureTask.Stream);
//System.Windows.Forms.Control.CheckForIllegalCrossThreadCalls = false;
double analogDataIn = reader.ReadSingleSample();//出现问题的语句
textBox1.Text = analogDataIn.ToString();
}
private void label1_Click(object sender, EventArgs e)
{
}
}
}