wp8 C#浏览器冻结

时间:2014-03-26 02:05:59

标签: c# windows-phone-8

我回来实现代码,但出了点问题。 只需浏览网页,浏览器即可冻结,锁定单元格并防止其关闭。他错过了什么? 请帮帮我! 我使用的代码就是这样:

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);
 }
}

1 个答案:

答案 0 :(得分:-1)

你只有一个for循环来确定这是否导致问题然后将其注释掉并循环并运行应用程序。如果它导致了问题,那么要么将它放在10循环后的try catch中,就会打破循环。