windows phone 8 - wp8 c#浏览器冻结

本文关键字:浏览器 冻结 wp8 phone windows | 更新日期: 2023-09-27 17:53:34

我回来实现代码,但有些事情是错误的。只要浏览网页,浏览器就会冻结,锁定单元格并阻止其关闭。他错过了什么?救救我吧!我使用的代码是这样的:

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

windows phone 8 - wp8 c#浏览器冻结

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