简体   繁体   English

wp8 C#浏览器冻结

[英]wp8 C# browser freezing

I'm back to implement a code, but something is going wrong. 我回去实现代码,但是出了点问题。 Simply by browsing the web, the browser freezes, locking the cell and preventing its closure. 只需浏览网络,浏览器就会冻结,锁定单元格并阻止其关闭。 What is he missing? 他想念什么? Help me please! 请帮帮我! The code I use is exactly this: 我使用的代码就是这样:

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

You only have one for loop to determine if this is causing the problem then comment it out and loop and run the app. 您只有一个for循环才能确定这是否是导致问题的原因,然后将其注释掉并循环并运行该应用程序。 If it is causing the problem then either put it in a try catch of after 10 loop break the loop. 如果是导致问题的原因,则将其放入10次循环的try catch中,然后中断循环。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM