<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Why not while(true)?</title><link>http://blogs.msdn.com/b/net_gadgeteer/archive/2011/12/19/why-not-while-true.aspx</link><description>Many programs have a basic structure of: 
 while ( true )
{
 // Program goes here 
} 
 This approach is logical if your program is responsible for monitoring user input, device I/O, threads, etc. However, it's not an optimal approach for most Gadgeteer</description><dc:language>en-US</dc:language><generator>Telligent Evolution Platform Developer Build (Build: 5.6.50428.7875)</generator><item><title>re: Why not while(true)?</title><link>http://blogs.msdn.com/b/net_gadgeteer/archive/2011/12/19/why-not-while-true.aspx#10250089</link><pubDate>Wed, 21 Dec 2011 19:01:27 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10250089</guid><dc:creator>Jay</dc:creator><description>&lt;p&gt;Hi Kerry,&lt;/p&gt;
&lt;p&gt;The thing is i didn&amp;#39;t want my handlers to be declared at the Program Thread i was kind of looking for a way to declare them at a different thread, that&amp;#39;s when i ran into the error that all module must be included in the Programs thread, which prompted using the above work around, and it works great, now i can add and declare Modules at will. and any time from any thread...&lt;/p&gt;
&lt;p&gt;the other issue that i have no solution to for now is releasing the module from the socket it is plugged into.. so if i attach a button to socket A i can&amp;#39;t release it from that socket and use that socket for another module....which is OK for now because you can plug and un-plug Modules while the board has power... maybe one day when Gadgeteer goes plug and play...&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10250089" width="1" height="1"&gt;</description></item><item><title>re: Why not while(true)?</title><link>http://blogs.msdn.com/b/net_gadgeteer/archive/2011/12/19/why-not-while-true.aspx#10249780</link><pubDate>Tue, 20 Dec 2011 23:49:42 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10249780</guid><dc:creator>Kerry Hammil</dc:creator><description>&lt;p&gt;Hi Jay,&lt;/p&gt;
&lt;p&gt;Glad you found the answer you needed - you can run your own dispatcher on a different thread than the program thread, and it will send events to the handlers registered on that thread. &amp;nbsp;You&amp;#39;ll still need some way to tell at startup which modules are plugged into which sockets though, correct? &amp;nbsp;I can&amp;#39;t think of a way to do that with Gadgeteer as it is today, unless you are feeding that information to the system via a storage or network device.&lt;/p&gt;
&lt;p&gt;-- Kerry&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10249780" width="1" height="1"&gt;</description></item><item><title>re: Why not while(true)?</title><link>http://blogs.msdn.com/b/net_gadgeteer/archive/2011/12/19/why-not-while-true.aspx#10249775</link><pubDate>Tue, 20 Dec 2011 23:25:08 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10249775</guid><dc:creator>Jay</dc:creator><description>&lt;p&gt;Got the answer i was looking for with the help of Architect &lt;a rel="nofollow" target="_new" href="http://www.breakcontinue.com"&gt;http://www.breakcontinue.com&lt;/a&gt; a great contributor to the .net micro framework...&lt;/p&gt;
&lt;p&gt;here is the code i came up with ..: and works great !&lt;/p&gt;
&lt;p&gt;void myMethod()&lt;/p&gt;
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Dispatcher.BeginInvoke(&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;new DispatcherOperationCallback(&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;delegate(object o)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Debug.Print(&amp;quot;Dispatch Called&amp;quot;);&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Gadgeteer.Modules.GHIElectronics.Button button;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;button = new GTM.GHIElectronics.Button(14);&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;button.ButtonPressed += new Button.ButtonEventHandler(button_ButtonPressed);&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;return null;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;), null&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;);&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;Cheers..&lt;/p&gt;
&lt;p&gt;Jay.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10249775" width="1" height="1"&gt;</description></item><item><title>re: Why not while(true)?</title><link>http://blogs.msdn.com/b/net_gadgeteer/archive/2011/12/19/why-not-while-true.aspx#10249743</link><pubDate>Tue, 20 Dec 2011 21:24:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10249743</guid><dc:creator>Jay</dc:creator><description>&lt;p&gt;Thank for sharing, ver informative.. and i have a question for you.&lt;/p&gt;
&lt;p&gt;So how do initialize module out side of the Dispatcher?&lt;/p&gt;
&lt;p&gt;Basically how do i do this:&lt;/p&gt;
&lt;p&gt;Gadgeteer.Modules.GHIElectronics.Button button;&lt;/p&gt;
&lt;p&gt;button = new GTM.GHIElectronics.Button(14);&lt;/p&gt;
&lt;p&gt;button.ButtonPressed += new Button.ButtonEventHandler(button_ButtonPressed);&lt;/p&gt;
&lt;p&gt;outside of &amp;nbsp;ProgramStarted() or after that dispatch has Exited ... right now i get the following error:&lt;/p&gt;
&lt;p&gt;&amp;quot;modules must be created on the Program&amp;#39;s Dispatcher thread&amp;quot;&lt;/p&gt;
&lt;p&gt;why i need to do this you ask? well because i need to be able to configure my Gadgeteer modules dynamically meaning i can load the program once and be able to plug and unplug modules later (NOT WHILE POWERED) and change the socket of the module and still be able to use it at runtime by recreate the class as mentioned above. &lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10249743" width="1" height="1"&gt;</description></item><item><title>re: Why not while(true)?</title><link>http://blogs.msdn.com/b/net_gadgeteer/archive/2011/12/19/why-not-while-true.aspx#10249717</link><pubDate>Tue, 20 Dec 2011 20:06:39 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10249717</guid><dc:creator>Ian Lee</dc:creator><description>&lt;p&gt;Great article! &amp;nbsp;This definitely solves some problems I&amp;#39;ve been having. &amp;nbsp;I wasn&amp;#39;t aware of this difference between Gadgeteer &amp;amp; NETMF. &amp;nbsp;Thanks!&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10249717" width="1" height="1"&gt;</description></item></channel></rss>