2016-01-29 39 views
0

使用TweetSharp我正在计算关注者列表。我怎样才能收回到ListBox如何在列表框中取消ListFollower?

下面是代码:

var options = new ListFollowerIdsOfOptions() { ScreenName = "PutinRF" }; 
do 
{ 
    if (cursor != null) 
     options.Cursor = cursor; 

    var followersList = ts.ListFollowerIdsOf(options); 

    //listBox1.Items.AddRange(followersList.ToArray()); 

    cursor = followersList.NextCursor; 

} while (cursor != 0); 

回答

1

尝试使用DataSource property

listBox1.DataSource = followersList; 

还是看下面的实现:

var allIds = new List<long>(); 
var options = new ListFollowerIdsOfOptions() { ScreenName = "PutinRF" }; 
var followersIds = ts.ListFollowerIdsOf(options); 
while (followersIds.NextCursor != 0) 
{ 
    options.Cursor = followersIds.NextCursor; 
    allIds.AddRange(followersIds); 
} 
listBox1.DataSource = allIds; 
+0

错误:System.OutOfMemoryException。 line:allIds.AddRange(followersIds); –

+0

@ArtemOlegovich请参阅[本文](http://stackoverflow.com/questions/8563933/c-sharp-out-of-memory-exception)。你尝试调试它吗?列表中有多少项?例如: – Marusyk

+0

:{ScreenName =“PutinRF”,Count = 20}。同样的错误=/ –

0

我的决定:

  var options = new ListFollowerIdsOfOptions { ScreenName = "PutinRF" }; 
      List<long> All_ods = new List<long>(); 
      TwitterCursorList<long> followerIDS = ts.ListFollowerIdsOf(options); 
      while(followerIDS.NextCursor!=null) 
      { 
       options.Cursor = followerIDS.NextCursor; 

       All_ods.AddRange(followerIDS.ToArray()); 
       //listBox1.Items.Add(All_ods.ToArray()); 
       listBox1.DataSource = All_ods; 
       label1.Text = "Получено: " + listBox1.Items.Count.ToString(); 
       break; 
      } 
+0

此解决方案与上述答案类似。我认为在while设置DataSource是不正确的 – Marusyk

相关问题