如何使这个运行异步?

编程入门 行业动态 更新时间:2024-10-18 19:28:13
本文介绍了如何使这个运行异步?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我写在C#中,并在其中一个WPF应用程序我需要查询历史TFS,而我显示的变更清单,我回去在ListView。

I am writing a WPF application in C# and in it I need to query history in TFS, and I'm displaying the list of changesets I get back in a listview.

ListView控件的ItemsSource绑定到称为变更一个IEnumerable属性,未加载,直到使用的属性:

The listview ItemsSource is bound to an IEnumerable property called Changesets that is not loaded until the property is used:

public IEnumerable<Changeset> Changesets { get { if (p_nChangesets == null) { p_nChangesets = TfsHelper.VCS.QueryHistory(Path, VersionSpec.Latest, 0, RecursionType.Full, null, new ChangesetVersionSpec(1), VersionSpec.Latest, int.MaxValue, false, true, false, false) .OfType<Changeset>(); } return p_nChangesets; } }

现在当视图加载时,列表视图绑定到此属性,因此它立即调用属性来获取变更集的收集发生的事情是。有时,这种查询缓慢运行,因此还需要一段时间,甚至看到窗口打开。我希望发生是立即窗口显示,直到该变更集被发现,然后列表视图被填充ListView控件是空的。但我不知道如何做到这一点。我试图用一个任务,但有相同的结果:

Now what happens is when the view loads, the listview is bound to this property so it immediately calls the property to get the collection of changesets. Sometimes this query runs slow so it takes a while to even see the window open. What I want to happen is the window displays immediately and the listview is empty until the changesets are found and then the listview is filled. But I don't know how to do this. I tried using a Task, but that had the same result:

public IEnumerable<Changeset> Changesets { get { if (p_nChangesets == null) { Task<IEnumerable> task = Task<IEnumerable>.Run(() => TfsHelper.VCS.QueryHistory( Path, VersionSpec.Latest, 0, RecursionType.Full, null, new ChangesetVersionSpec(1), VersionSpec.Latest, int.MaxValue, false, true, false, false)); p_nChangesets = task.Result.OfType<Changeset>(); } return p_nChangesets; } }

显然,我不知道我有任务在做。有谁知道如何使这个做我想要什么?

Clearly, I don't know what I'm doing with tasks. Does anyone know how to make this do what I want?

推荐答案

添加 IsAsync = TRUE 在XAML中绑定:

Add IsAsync=True in your binding in XAML:

<ListView ItemsSource="{Binding ChangeSets, IsAsync=True}"/>

更多推荐

如何使这个运行异步?

本文发布于:2023-11-13 00:34:29,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1582919.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!