Responsive GUI using Multi-threading in C# Winforms

前端 未结 2 548
被撕碎了的回忆
被撕碎了的回忆 2021-01-14 15:49

I have a child form in my application. This form has got about more than 50 comboboxes and everyone is getting data from database. All combobexs are loaded in the load event

相关标签:
2条回答
  • 2021-01-14 16:04

    Use task parallel library, which is included in .NET starting from version 4 or Parallel Extensions. Samples of using TPL you can find here

    And read more about it here.:

    http://bradwilson.typepad.com/blog/2012/04/tpl-and-servers-pt1.html

    http://www.codeproject.com/Articles/30975/Parallel-Extensions-for-the-NET-Framework-Part-I-I

    http://blogs.msdn.com/b/csharpfaq/archive/2010/06/01/parallel-programming-in-net-framework-4-getting-started.aspx

    http://thenewtechie.wordpress.com/2012/01/03/introduction-to-tpl-part-1/

    Reactive Exensions are a little bit harder. But anyway good. Samples here. Some introduction to it here:

    http://www.codeproject.com/Articles/47498/A-quick-look-at-the-Reactive-Extensions-Rx-for-Net

    http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/2010/08/18/reactive-extensions-for-net-stuff-happens.aspx

    Anyway you can find very easy more information.

    Speaking about BackgroundWorker. It's good solution for winforms. But this approach is outdated. TPL or Rx are new approaches, more perfomant, more comfortable, especial when you have to much controls. Having so much controls with async operation is also a question to UI design, maybe it should be changed. Anyway BackgroundWorker also a good choice and it's up to you what select.

    0 讨论(0)
  • 2021-01-14 16:06

    Take a look at the BackgroundWorker class. This can do exactly what you want. You can also include something like a progress bar to show users the data is still being loaded before they go ahead and do stuff in your child form.

    0 讨论(0)
提交回复
热议问题