如何同时使用多线程来更新aspx页面 [英] How to update aspx page while using Multithreading

查看:873
本文介绍了如何同时使用多线程来更新aspx页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用多线程来更新/显示页面的内容。网页使用多个(和嵌套的)更新面板。现在,我用下面的逻辑更新页面。

I am using multi-threading to update/display the content of page. Page is using multiple ( and nested ) update panels. Right now, i am using following logic to update page.

我有七个线程,每个线程的数据通过查询数据库,并在页面的特定部分显示出来。我们启动线程,等待2薄荷糖,经过2薄荷糖后,如果某些线程仍在工作,然后我们打破这些,并显示页面上的人口数据,这些调用线程正在对页面加载事件。

I have seven threads, each thread gets data by querying database and display them in specific section of page. We start threads and wait for 2 mints, after passing 2 mints if some threads still working then we break those and display the populated data on page, these calls to thread are making on page load event.

问题这里要说的是,我们必须要等到具体的时间网页加载之前,然后在时间的限制,网页后,会用填充的数据显示。用户需要等待较长看到的网页,这使得一个非常糟糕的IM pression。

Problem here is that we must need to wait for specific time before page load, and then after that time limit, page 'll be displayed with populated data. Users need to wait for long to see the page, which making a really bad impression.

如果我们去掉2薄荷糖的极限,那么网页渲染速度快,但它并没有显示所有数据。

If we remove the limit of 2 mints, then page rendered fast but it does not display all data.

我想在这里什么,当我们调用线程,我们不需要等待所有,当一个线程完成它应该显示页面上的数据,并尽快其他线程是完整的那么就应该相应地显示自己的数据。

What i want here, when we call threads, we don't need to wait for all, when one thread completes it should show its data on page, and as soon as other threads being complete then they should display their data accordingly.

推荐答案

我发现这个问题的解决方案测试多种技术后。

I found solution of this problem after testing many techniques.

要实现这一点,我们并不需要使用线程。当我们调用一个页面,服务器使这些页面的对象,并执行所有必需的执行,然后使这个页面,破坏其目标服务器发送呈现的页面给客户端浏览器。因此,在渲染之后,我们不能接收线程的回应。要接收线程的回应,我们必须阻止页面被明确地呈现(它引起的延迟,这是我们不希望)。

To implement this, we don't need to use threading. When we call a page, server makes an object of this page and perform all required executions and then it render this page, destroy its object on server and send rendered page to Client Browser. So after rendering we can't receive thread's response. To receive thread's response, we must have to stop page being rendered explicitly (it causes delay, which we don't want).

因此​​,我们的解决方案是使用JSON AJAX API与Web方法(与序列化和反序列化,如果你是在处理复杂的对象)。

So our solution is using JSON Ajax API with Web Methods (with Serialization and Deserialization if you are dealing with complex objects).

我们必须与它的所有控件,页面的onload事件加载页面,调用使用JSON API,从Web方法接收应答之后,调用Web方法JavaScript方法,我们需要手动更新使用JavaScript / JQuery的各自的控制。

We have to load page with all controls on it, onload event of page, call javascript method which call Web Method using JSON API, after receiving response from Web Method, we have to update respective controls using JavaScript/JQuery manually.

这篇关于如何同时使用多线程来更新aspx页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆