开发者

Is there a code template/design pattern I can use when reacting to mouse clicks or button presses? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

One of the problems that I constantly see with Winforms applications is that the GUI thread is stuck while a long-running task is running or just plain stops refreshing (yes, I know - needs threading).

Is there a code template/design pattern I can use when reacting to mouse clicks or button presses? Should there be a p开发者_StackOverflow中文版rocessing thread always running in the GUI app?

Basically, how do I write a great Winforms Application that is easy to maintain and doesn't have any quirky refresh bugs?


BackgroundWorker


Assuming your question is you are looking for a Solid Respectable Framework for GUI on .net then I say Look at Prism or Caliburn.


You should look into the new Async CTP here: http://msdn.microsoft.com/en-us/vstudio/gg316360

And tutorial here: http://geekswithblogs.net/mbcrump/archive/2010/10/28/visual-studio-async-ctp-for-the-rest-of-ushellip.aspx

Regardless of the method to deliver the UI the new Async CTP provides simple solutions to GUI threading and responsiveness.

Follow n-tier development practices, use unit testing and coded UI testing(MSTest for instance), and profile your application to find bottlenecks and memory issues.


Start by opening VS2010 and creating a new C# Winforms app. Run it, it should be fine.

Use the forms designer to add controls and event handlers.

If the event handler does something that is slow, add a background worker component, and put the slow code in the event handler it provides for a separate thread.

The UI thread will be responsive as long as you don't slow it down with code in an event handler.

My best advice is for you to believe that writing responsive winforms apps is not only possible, but really pretty easy with modern development tools. If you followed the above and have a specific wierdness then post the specific thing as a question, and you'll probably get help.

Also, you don't have to get fancy for simple apps - I just transitioned to the MVP pattern after more than 6 months of iterations on a fairly advanced LOB app project. I'm looking at MVVM now, but won't start really using it until I see the advantage.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜