views:

49

answers:

2

Hi,

After developing ASP.NET apps exclusively for several years I'm about to start developing Winforms apps. What are the gotchas that I should be looking out for with this changes? For instance the way object lifetime is managed in the winforms paradigm. I'm sure there must be plenty of gotchas / differences between the two that I need to be mindful of.

Thanks.

+3  A: 

There are many gotchas going from Winforms to ASP.NET. However going the other way you might just experience a breath of fresh air since it's all running in process and you have a fully stateful environment, meaning things won't disappear and be rebuilt.

At times you will be confused because you're still thinking in ASP.NET and the Winforms way is too easy. Prepare to bang your head against the desk and repeat "stupid, stupid, stupid... it's so obvious" and stuff like that.

  • No more stateless stuff (postback, viewstate, control state, waiting until controls are ready, etc)
  • No more application recycling
  • No AJAX callbacks or page redirects - No more request/response UI model
  • Everything just persists there and exists as you last left it.
  • You can still use all the middle-tier and backend stuff you're accustomed to (non-UI) so that will feel really comfortable and takes care of a lot of the transition

However
Layout and design will feel a little more stringent compared to the natural flow of HTML and its application of CSS style separately.
For a more beautiful and richer UI you might want to consider WPF to succeed your Winform endeavours. This Microsoft section provides info on both technologies.

There will be a transition of course as you learn the classes specific to Winforms, however they feel similar to the ASP.Net versions, just simpler to implement.

John K
Good answer! +1
Cylon Cat
+2  A: 

In addition to @jdk's excellent answer...

  • You have to be very careful to keep the Winform responsive. That means learning to do threading and background tasks. Look up the BackgroundWorker class.
  • Validation works a lot differently.
  • You'll find yourself coding a lot more events. For sanity's sake, move as much of the data handling out of the code-behind as you can.
Cylon Cat