2014-03-26 117 views
0

我回来执行代码,但出了问题。 只需浏览网页,浏览器就会冻结,锁定单元并阻止其关闭。他错过了什么? 请帮助我! 我使用的代码正好是这样的:wp8 C#浏览器冻结

public partial class MainPage : PhoneApplicationPage 
{ 
    private const int NumTabs = 10; 

    private int currentIndex; 
    private string[] urls = new string[NumTabs]; 
    private WebBrowser[] browsers = new WebBrowser[NumTabs]; 

    public MainPage() 
{ 
    InitializeComponent(); 
    ShowTab(0); 
} 

private void ShowTab(int index) 
{ 
    this.currentIndex = index; 
    UrlTextBox.Text = this.urls[this.currentIndex] ?? ""; 
    if (this.browsers[this.currentIndex] == null) 
    { 
     WebBrowser browser = new WebBrowser(); 
     this.browsers[this.currentIndex] = browser; 
     BrowserHost.Children.Add(browser); 
    } 
    for (int i = 0; i < NumTabs; i++) 
    { 
     if (this.browsers[i] != null) 
     { 
      this.browsers[i].Visibility = i == this.currentIndex ? Visibility.Visible : Visibility.Collapsed; 
     } 
    } 
} 

private void UrlTextBox_KeyDown(object sender, KeyEventArgs e) 
{ 
    if (e.Key == Key.Enter) 
    { 
     Uri url; 
     if (Uri.TryCreate(UrlTextBox.Text, UriKind.Absolute, out url)) 
     { 
      this.urls[this.currentIndex] = UrlTextBox.Text; 
      this.browsers[this.currentIndex].Navigate(url); 
     } 
     else 
      MessageBox.Show("Invalid url"); 
    } 
} 

private void TabMenuItem_Click(object sender, EventArgs e) 
{ 
    int index = Int32.Parse(((ApplicationBarMenuItem)sender).Text) - 1; 
    ShowTab(index); 
} 
} 
+0

这就像他进入了一个无限循环... –

回答

-1

你只有一个for循环,以确定这是否是引起那么问题注释掉和循环,并运行应用程序。如果它导致问题,那么要么在10次循环中断循环之后尝试捕获它。

+0

你认为是值10导致循环的NumTabs。 '私人const int NumTabs = 10;' 你能告诉我该怎么做吗,因为我对这个主题很陌生。我谢谢你 –