Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

Best practice for repetitive task like a "Led blinking thread"

led thread threading loop sleep best practice

  • Please log in to reply
2 replies to this topic

#1 NeonMika / Markus VV.

NeonMika / Markus VV.

    Advanced Member

  • Members
  • PipPipPip
  • 209 posts
  • LocationUpper Austria

Posted 28 March 2013 - 08:03 AM

Hey ho!

I'm not sure if there is something like a "best practice" for this, but:

I'm currently using the following code to blink my led in a fixed duration.

 

 

Thread t = new Thread(			    new ThreadStart(				    delegate( )				    {					    while ( true )					    {						    //Debug.Print(Debug.GC(true).ToString());						    ledPort.Write(true);						    Thread.Sleep(30);						    ledPort.Write(false);						    Thread.Sleep(2000);					    }				    }				    ));t.Start( ); 

 

I have in mind there was some other method (something called like AutoResetEvent or something in this direction)

So now my question is: What is the best way to solve such repetitive actions like led blinking, etc.

What is most energy and performance efficient?

 

Greets, Markus


NeonMika.Webserver
> Control your N+ and write webservice methods easyily
> Receive data from you N+ (in XML or JSON)
> Browse the SD on your N+ directly in the browser and d
own - and upload files

 

If you need help with NeonMika.Webserver, please just leave a note in the thread and/or contact me via Skype :)

 

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
--- Mistakes teach you important lessons. Every time you make one, you are one step closer to your goal. ----
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------


#2 Nevyn

Nevyn

    Advanced Member

  • Members
  • PipPipPip
  • 1072 posts
  • LocationNorth Yorkshire, UK

Posted 28 March 2013 - 08:24 AM

I would use a Timer for this.  If you want to know how to use them then have a look at this post.

 

Regards,

Mark


To be or not to be = 0xFF

 

Blogging about Netduino, .NET, STM8S and STM32 and generally waffling on about life

Follow @nevynuk on Twitter


#3 NeonMika / Markus VV.

NeonMika / Markus VV.

    Advanced Member

  • Members
  • PipPipPip
  • 209 posts
  • LocationUpper Austria

Posted 03 April 2013 - 05:00 PM

Thanks for the post link, I will have a look at it :)

 

If anyone else has other information, I'm always happy.

 

Greets, Markus


NeonMika.Webserver
> Control your N+ and write webservice methods easyily
> Receive data from you N+ (in XML or JSON)
> Browse the SD on your N+ directly in the browser and d
own - and upload files

 

If you need help with NeonMika.Webserver, please just leave a note in the thread and/or contact me via Skype :)

 

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
--- Mistakes teach you important lessons. Every time you make one, you are one step closer to your goal. ----
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------






Also tagged with one or more of these keywords: led, thread, threading, loop, sleep, best practice

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.