12-04-2012 04:34 PM
I've been using DaqSystem.Local.Devices to get a list of analog input channels. Recently, I noticed that it takes about 90 seconds for the first call, but very fast for subsequent calls. I am using Visual Studio 2010, C# language, .NET Framework 4.0, Measurement Studio 2010 SP1, and NIDAQmx 940f1
Below are the code fragment and output. It is slow whether or not I have hardware connected.
Any suggestions?
private void Form1_Load(object sender, EventArgs e)
{
Console.WriteLine("Before: " + DateTime.Now.ToLongTimeString());
Console.WriteLine(DaqSystem.Local.Devices.Length);
Console.WriteLine("Middle: " + DateTime.Now.ToLongTimeString());
Console.WriteLine(DaqSystem.Local.Devices.Length);
Console.WriteLine("After: " + DateTime.Now.ToLongTimeString());
}
Before: 2:09:54 PM
0
Middle: 2:11:24 PM
0
After: 2:11:24 PM
12-05-2012 06:13 PM
Hi HLee
I think what is happening is that when the function is called originally it is the first time it is reserving the resource which is taking longer, Are you communicating with the device at any point previous to this in the code?
12-06-2012 10:52 AM
I would hazard a guess that the complier is optimizing your code for you and only doing the call once.