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

Better way to synchronizing emulator and GUI thread


  • Please log in to reply
6 replies to this topic

#1 Paolo Patierno

Paolo Patierno

    Advanced Member

  • Members
  • PipPipPip
  • 169 posts
  • LocationItaly

Posted 28 September 2010 - 04:47 PM

Hello, I haven't found a .Net Micro Framework forum for general questions on it so I think that I may receive a good answer here ! I have a checkbox on a form emulator that emulate a gpio input port. To synchronizing emulator thread and GUI thread I have to use BeginInvoke on gpio port. I have found the four following ways to specify the delegate : delegate void WriteDelegate(bool state); private void gpioIn0CheckBox_CheckedChanged(object sender, EventArgs e) { // 1 : this.gpioIn0.BeginInvoke(new Action<bool>(this.gpioIn0.Write), this.gpioIn0CheckBox.Checked); // 2 : this.gpioIn0.BeginInvoke(new MethodInvoker(() => this.gpioIn0.Write(this.gpioIn0CheckBox.Checked))); // 3 : this.gpioIn0.BeginInvoke(new MethodInvoker(delegate { this.gpioIn0.Write(this.gpioIn0CheckBox.Checked); } )); // 4 : this.gpioIn0.BeginInvoke(new WriteDelegate(this.gpioIn0.Write), this.gpioIn0CheckBox.Checked); } I think that the 1 and 4 are equal and I prefer the first (we avoid to define the delegate). The 2 and 3 are equal too, the difference is the use of lambda expression in the 2 and anonymous delegate in the 3. What do you think ? Thanks, Paolo

Paolo Patierno

Microsoft MVP on Windows Embedded & IoT

Azure Advisor

Twitter : @ppatierno
Linkedin : paolopatierno
Blog : DevExperience

Blog : Embedded101
?


#2 c_johnson

c_johnson

    Member

  • Members
  • PipPip
  • 11 posts

Posted 28 September 2010 - 05:41 PM

Hi Paolo, To help you out we've done quite a bit of work on the emulator front of things. Pleas visit our codeplex website: http://netduinoemulator.codeplex.com/ were you can read more about it. If your really intrested in lending a hand please feel free to send any of us on the site a PM (were also members of the forum) Other than this our source may be able to help you out or save you the effort. I would suggest if you want to get your emulator working you check out the older versionn as the newer version use's MVVM archetecture whicch if you haven't used it before may be daunting. The new version is availavle here : http://netduinoemula...ist/changesets# You will get more files than you need but if you work with the Netduino Emulator V1.275 folder that is the most up to date. If you want to play with a bit more the older version is available: http://netduinoemula...wnloadId=147473 This has buttons/toggle switchs and LED/DC motors to play with. Take Care Chris NetduinoEmulator Team

#3 Paolo Patierno

Paolo Patierno

    Advanced Member

  • Members
  • PipPipPip
  • 169 posts
  • LocationItaly

Posted 01 October 2010 - 06:44 AM

Hi Paolo,

To help you out we've done quite a bit of work on the emulator front of things. Pleas visit our codeplex website: http://netduinoemulator.codeplex.com/ were you can read more about it.

If your really intrested in lending a hand please feel free to send any of us on the site a PM (were also members of the forum) Other than this our source may be able to help you out or save you the effort. I would suggest if you want to get your emulator working you check out the older versionn as the newer version use's MVVM archetecture whicch if you haven't used it before may be daunting.

The new version is availavle here : http://netduinoemula...ist/changesets#

You will get more files than you need but if you work with the Netduino Emulator V1.275 folder that is the most up to date.

If you want to play with a bit more the older version is available: http://netduinoemula...wnloadId=147473

This has buttons/toggle switchs and LED/DC motors to play with.

Take Care
Chris

NetduinoEmulator Team


I will see the Netduino Emulator source code but regarding my question ?
Thanks, Paolo.

Paolo Patierno

Microsoft MVP on Windows Embedded & IoT

Azure Advisor

Twitter : @ppatierno
Linkedin : paolopatierno
Blog : DevExperience

Blog : Embedded101
?


#4 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 01 October 2010 - 06:48 AM

I personally use #3 most of the time--but #2 is nice because it's more condensed. It's largely a matter of style--but the reason I like #3 is because it's relatively clear "what is going on". But then again, the same could be said for #2. Chris

#5 Paolo Patierno

Paolo Patierno

    Advanced Member

  • Members
  • PipPipPip
  • 169 posts
  • LocationItaly

Posted 01 October 2010 - 06:59 AM

I personally use #3 most of the time--but #2 is nice because it's more condensed.

It's largely a matter of style--but the reason I like #3 is because it's relatively clear "what is going on". But then again, the same could be said for #2.

Chris


I understand that in #4 solution we need to define a new delegate type so we can discard it but why do you prefer MethodInvoker delegate to Action delegate ?

Thanks,
Paolo

Paolo Patierno

Microsoft MVP on Windows Embedded & IoT

Azure Advisor

Twitter : @ppatierno
Linkedin : paolopatierno
Blog : DevExperience

Blog : Embedded101
?


#6 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 01 October 2010 - 07:24 AM

I prefer #2 and #3 (and especially #3) because it's easier for beginning-to-intermediate users to understand what's going on. Matter of style I suppose. We traditionally use #3 in our own code for clarity--but are considering a switch to #2 in the future. Chris

#7 Paolo Patierno

Paolo Patierno

    Advanced Member

  • Members
  • PipPipPip
  • 169 posts
  • LocationItaly

Posted 01 October 2010 - 07:36 AM

I prefer #2 and #3 (and especially #3) because it's easier for beginning-to-intermediate users to understand what's going on. Matter of style I suppose.

We traditionally use #3 in our own code for clarity--but are considering a switch to #2 in the future.

Chris


So you have discarded the use of Action delegate ?

Paolo Patierno

Microsoft MVP on Windows Embedded & IoT

Azure Advisor

Twitter : @ppatierno
Linkedin : paolopatierno
Blog : DevExperience

Blog : Embedded101
?





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.