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

Asynchronous Delegates


  • Please log in to reply
2 replies to this topic

#1 Jim

Jim

    Member

  • Members
  • PipPip
  • 22 posts

Posted 21 April 2012 - 08:31 PM

I'm sending a message to a gainspan wifi to serial bridge and waiting for the entire response to come back (lets pretend its an HTTP GET). I'm looping while checking to see if the message has been received back yet and returning when it does. Obviously this blocks the main thread so I created a delegate pointing to the blocking method and called BeginInvoke. However, when I run the code it compiles, deploys, runs, and gives a NotSupportedException on BeginInvoke. Are asynchronous methods really not allowed? I read once that spinning up new threads in .NET requires ~1MB of memory, does that sound right for the .NET MF as well? I'd rather do it asynchronously since I can use callbacks and anonymous methods to make my code much cleaner and use fewer resources.

#2 ErikN

ErikN

    Advanced Member

  • Members
  • PipPipPip
  • 119 posts
  • LocationNew York, NY

Posted 21 April 2012 - 10:10 PM

NETMF uses software threading and from code I've written and what I've seen from others, you can do asynchronous programming. I haven't specifically used Begin- and EndInvoke rather using Thread and ThreadStart.

#3 Jim

Jim

    Member

  • Members
  • PipPip
  • 22 posts

Posted 24 April 2012 - 04:27 PM

NETMF uses software threading and from code I've written and what I've seen from others, you can do asynchronous programming. I haven't specifically used Begin- and EndInvoke rather using Thread and ThreadStart.

Spinning up a new thread isn't the same as asynchronous. You're adding another thread to the mix who's job is usually to loop and wait for something to happen and then die. Asynchronous is better because you make a phone call to a piece of code, tell it to do some work and call you back to you when it's finished. It seems like the same thing but it's not since there's only 1 thread which is multitasking. I would be surprised if this isn't supported in .NET MF since threads take more resources.




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.