English 中文(简体)
图4.5 与世界森林论坛的 as事处理者不敏感
原标题:Unresponsiveness with async event handlers in WPF in .NET 4.5

我创建了一个简单的“合成”行动,它正在被点击时被踢。 这里是整个法典:

public partial class MainWindow : Window {

    public MainWindow() {
        InitializeComponent();
    }

    private async void Button_Click_1(object sender, RoutedEventArgs e) {

        var htmlString = await DowloadPage("http://example.com");
        txtBlock1.Text = htmlString;
    }

    public async Task<string> DowloadPage(string uri) {

        using (WebClient client = new WebClient()) {

            var htmlString = await client.DownloadStringTaskAsync(uri);
            return htmlString;   
        }
    }

}

非常容易。 但是,当我点击 but子时,我对“倡议”的透视无动于衷。 当我试图在下载网页时绕过窗户时,我无法做到。

任何想法什么是错的?

Edit:

我与HttpClient一道在NET 4.5中进行了审判,并按预期做了大量工作:

public async Task<string> DowloadPage(string uri) {

    using (HttpClient client = new HttpClient()) {

        var response = await client.GetAsync(uri);
        var htmlString = await response.Content.ReadAsStringAsync();
        return htmlString;   
    }
}
最佳回答

,但不幸的是 rel=“noretinger” 。 这至少是阻碍国家安全局的监视。 它也可能在代理谈判和(或)最初的吉大港山区伙伴关系中受阻。

<代码>HttpClient的较早的发布正使用<代码>上的包装。 HttpWebRequest。 I requested a real-asynchronous HttpClient,但从未听到过答复。 上一次我检查了<代码>HttpClient,该编码仍然属于MVC;ASP。 NET 当时,网站标注号为t,因此从那时起,它们可能已经固定<代码>HttpClient>。

问题回答

暂无回答




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签