需要一个WPF的例子 [英] Need an example for WPF

查看:100
本文介绍了需要一个WPF的例子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对WPF很新。我想要一个多任务的例子。基本上我在主视图上有一个启动按钮,单击它然后有几个长任务同时运行,但最大任务数量是有限的。



我尝试了一些运动说让两个任务运行,但我只发现一个任务运行而另一个被阻止。我不确定WPF会阻止它。



我还没有在网上找到这样的例子。我觉得在WPF中处理多个线程很难。

BTW,学习WPF的最佳资源是什么?

解决方案

zhshqzyc写道:

@SA,我对Invoke或BeginInvoke的理解仅适用于UI?我们可以将它们用于长时间运行的后端进程吗?

你是对的。如果你想将一些执行委托给其他线程,这是一个完全不同的问题 - 你必须自己实现这样的行为。



我的文章,完整的源代码代码和用法示例,解释一下:用于线程通信的简单阻塞队列和线程间调用 [ ^ ]。



使用.NET v.4.0及更高版本,Microsoft集合的实现速度更快(http://msdn.microsoft.com/en-us/library/dd267312%28v= vs.110%29.aspx [ ^ ]),但是,与MSDN文档相比,艺术icles解释了内部结构并提供了更高级的用例和使用说明。



-SA


< blockquote>学习:线程, Dispatcher.Invoke Dispatcher.BeginInvoke

现在,你知道要搜索的关键字。首先,做一些搜索和阅读主题。在阅读时,你会发现成千上万的代码样本,如果不是数百万。



寻找的地方之一是CodeProject的文章和答案:

http://www.codeproject.com/search。 aspx?q = WPF +%28Invoke + OR + BeginInvoke%29& doctypeid = 1 [ ^ ],

http://www.codeproject.com/search.aspx?q=WPF+%28Invoke+OR+BeginInvoke%29&doctypeid=5 [ ^ ]。



通过这种方式,您可以获得更少的搜索结果,但大多数搜索结果几乎都能保证相关性。



-SA


I am pretty much new to WPF. I want an example for multiple tasks. Basically I have a start button on the mainview, click it then there are several long tasks concurrently running, but the the maximum number of tasks are limited.

I tried some exercise say letting two tasks running, however I only found one task run and the other was blocked. I am not sure if WPF blocks it.

I haven't found such an example online. I feel it is hard to handle multiple thread in WPF.
BTW, what is the best resource to learn WPF?

解决方案

zhshqzyc wrote:

@SA, My understanding for Invoke or BeginInvoke is only for UI? Can we use them for long running back end process?

You are right. If you want to delegate some execution to some other thread, this is a totally different issue — you have to implement such behavior yourself.

My article, complete with full source code and usage examples, explains it all: Simple Blocking Queue for Thread Communication and Inter-thread Invocation[^].

With .NET v.4.0 and later, there is a faster Microsoft implementation of the collection (http://msdn.microsoft.com/en-us/library/dd267312%28v=vs.110%29.aspx[^]), but, in contrast to MSDN documentation, by articles explains the internals and provides more advanced use cases and explanations of the usage.

—SA


Learn: threading, Dispatcher.Invoke, Dispatcher.BeginInvoke.
Now, you know the keywords to search for. First, do some search and read on the topics. While reading, you will find thousands of code samples, if not millions.

One of the place to look for is CodeProject articles and answers:
http://www.codeproject.com/search.aspx?q=WPF+%28Invoke+OR+BeginInvoke%29&doctypeid=1[^],
http://www.codeproject.com/search.aspx?q=WPF+%28Invoke+OR+BeginInvoke%29&doctypeid=5[^].

This way, you will get much less search results, but the relevance will be nearly guaranteed for most of them.

—SA


这篇关于需要一个WPF的例子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆