Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gotchas of moving from developing ASP.NET to Winforms apps

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.

like image 970
Peanut Avatar asked Jun 05 '10 23:06

Peanut


People also ask

Does .NET core support WinForms?

In this article. Windows Forms support was added to . NET Core in version 3.0.

Does ASP net Core support Web Forms?

ASP.NET Web Forms isn't supported in ASP.NET Core (nor are ASP.NET Web Pages). Typically, the functionality of these pages must be rewritten when porting to ASP.NET Core. There are, however, some strategies you can apply before or during such migration to help reduce the overall effort required.

Does .NET Core 5 support WinForms?

NET 5 / . NET 6 extends support for desktop technologies - WinForms and WPF, and continues to unify all . NET development frameworks.


2 Answers

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.

like image 170
John K Avatar answered Sep 28 '22 05:09

John K


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.
like image 45
Cylon Cat Avatar answered Sep 28 '22 04:09

Cylon Cat