我正在开发Windows Phone 7的twitter应用程序,并且一直在做一些原型设计。在应用程序中缩小某些对象时遇到了问题。下面的代码只是挂起(没有动作,搜索不会更新),除非我注释掉Dispatcher.BeginInvoke(new ThreadStart (doProgressBar));
我也尝试使用后台工作线程运行doProgressBar()
,但效果相同。坚持一个断点表明它确实击中了doProgressBar()
,这似乎是正常工作。Windows Phone 7线程问题
任何帮助我了解什么是错的将不胜感激。我不明白为什么我至少看不到进度条更新。我也很困惑为什么主线程在另一个线程中运行时会挂起。可能有一些关于我需要了解的移动应用程序中的线程?
public MainPage()
{
InitializeComponent();
}
private void ProcessIncommingSearch(TwitterSearchResult searchResult, TwitterResponse response)
{
if (response.StatusCode == HttpStatusCode.OK)
{
foreach (var status in searchResult.Statuses)
{
TwitterStatus inline = status;
Tweet tweet = new Tweet(inline);
Dispatcher.BeginInvoke(() => lboxTweets.Items.Add(tweet));
}
}
}
private void image1_ManipulationStarted(object sender, ManipulationStartedEventArgs e)
{
Dispatcher.BeginInvoke(() => lboxTweets.Items.Clear());
Dispatcher.BeginInvoke(new ThreadStart (doProgressBar));
TwitterService ts = GlobalVariables.Service();
ts.Search(txtSearch.Text, ProcessIncommingSearch);
}
private void doProgressBar()
{
while (progressBar1.Value <= 100)
{
progressBar1.Value += 1;
}
}
private void txtSearch_GotFocus(object sender, RoutedEventArgs e)
{
txtSearch.Text = "";
}
private void txtPage_ManipulationStarted(object sender, ManipulationStartedEventArgs e)
{
throw new NotImplementedException();
}
您是否使用silverlight工具包中的常规进度条或性能进度条?它是什么TwitterService?自制或现有的图书馆? – 2011-03-12 12:27:50
这里是进度条的xaml 。 Twitterservice来自tweetsharp库。它工作正常,没有进度条更新。 –
2011-03-12 17:23:20