direct data reading without AccelerationChangeEventHandler

Supporting Visual Studio on Windows
sgazaix
Phidgetsian
Posts: 9
Joined: Tue Mar 11, 2008 3:46 am
Location: France

direct data reading without AccelerationChangeEventHandler

Postby sgazaix » Sun Aug 21, 2011 3:58 pm

I am trying to read the acceleration without accel.AccelerationChange += new AccelerationChangeEventHandler(accel_AccelerationChange);
--------
void accel_AccelerationChange(object sender, AccelerationChangeEventArgs e)


No problem with Visual C# 2010 in Console application :
for (int i = 0; i < 200000; i++)
{x = accel.axes[0].Acceleration;
Console.WriteLine("acceleration=" + x);}
I collect the data with accuracy and speed.

With Visual C# 2010 in a Windows.Form application,
the code is :
double Ax,Ay,Az;
for (int i = 0; i < 100; i++)
{
Ax = accel.axes[0].Acceleration;
Ay = accel.axes[1].Acceleration;
Az = accel.axes[2].Acceleration;
textBox1.Text = accel.axes[0].Acceleration.ToString(); }

The code compile fine, but the data keeps the same value during all iterations of i !! !

What's wrong ???

User avatar
Patrick
Lead Developer
Posts: 3155
Joined: Mon Jun 20, 2005 8:46 am
Location: Canada
Contact:

Re: direct data reading without AccelerationChangeEventHandl

Postby Patrick » Mon Aug 22, 2011 9:11 am

Where are you updating your form from? It must be from a separate thread, or you would be locking up your GUI with that code. If it is from a separate thread, then you really need to be calling invoke to do your cross-thread gui access.

What is your reason for not wanting to use events? Generally you would use events in a GUI based application, and polling in a console app.

-Patrick

sgazaix
Phidgetsian
Posts: 9
Joined: Tue Mar 11, 2008 3:46 am
Location: France

Re: direct data reading without AccelerationChangeEventHandl

Postby sgazaix » Wed Aug 24, 2011 5:50 pm

My reason for not using events : well, just to try ...

I am now trying to figure out the "Invoke maze" ...

sgazaix
Phidgetsian
Posts: 9
Joined: Tue Mar 11, 2008 3:46 am
Location: France

Re: direct data reading without AccelerationChangeEventHandl

Postby sgazaix » Thu Aug 25, 2011 2:52 pm

Well ...
I can't figure out how to use Invoke and all that stuff.
MSDN example are about Windows.Form.Control thread, which is not exactly the same problem.



Just for fun, I would be pleased if you could post maybe ten lines of C#, explaining how to avoid thread Locking WITHOUT using AccelerationChangeEvent.

another way to explain my question :
How to translate in Windows terms the following Console Application code ???

for (int i = 0; i < 20000
{
double x;
x = accel.axes[0].Acceleration;
Console.WriteLine("acceleration read WITHOUT AccelerationChangeEvent" + x);
}

Thanks ...


Return to “C#.NET”

Who is online

Users browsing this forum: No registered users and 1 guest