且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

WPF VSTS应用程序挂在VS凭据提示上

更新时间:2021-08-09 22:53:09

您需要启动另一个线程来执行该操作(例如System.Threading.Tasks.Task.Run).

You need to start another thread to execute that (e.g. System.Threading.Tasks.Task.Run).

例如:

private void button_Click(object sender, RoutedEventArgs e)
        {
            var workitem = System.Threading.Tasks.Task.Run(() => GetItems(123)).Result;

        }
 public WorkItem GetItems(int itemId)
        {
            var myCredentials = new VssClientCredentials();
            var vstsConnection = new VssConnection(new Uri(@"https://XXX.visualstudio.com/"), myCredentials);
            var vstsClient = vstsConnection.GetClient<WorkItemTrackingHttpClient>();
            var workItem = vstsClient.GetWorkItemAsync(itemId).Result;

            return workItem;
        }

另一方面,您可以直接在代码中指定帐户(可以让用户使用自定义登录窗口来提供帐户).

On the other hand, you can specify account in your code directly (could be let user to provide account by using a custom login window).

var u = new Uri("XXX");
VssCredentials c = new VssCredentials(new Microsoft.VisualStudio.Services.Common.WindowsCredential(new NetworkCredential("[user name]", "[password]")));
var connection = new VssConnection(u, c);