如何在使用多线程时更新 aspx 页面

How to update aspx page while using Multithreading(如何在使用多线程时更新 aspx 页面)
本文介绍了如何在使用多线程时更新 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 mints,如果某些线程仍在工作,则在传递 2 mints 之后我们中断它们并在页面上显示填充的数据,这些对线程的调用是在页面加载事件上进行的.

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.

问题 这里是我们必须在页面加载之前等待特定时间,然后在该时间限制之后,页面将显示填充数据.用户需要等待很长时间才能看到页面,这给人留下了非常糟糕的印象.

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 mints 的限制,则页面渲染速度很快,但不会显示所有数据.

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 Method 的 javascript 方法,在收到 Web Method 的响应后,我们必须使用 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 页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

C# Windows Application - Many threads using the same connection?(C# Windows 应用程序 - 许多线程使用相同的连接?)
How to execute a block of code only once on a multithreading environment?(如何在多线程环境中只执行一次挡路代码?)
Multithreaded .NET queue problems(多线程 .NET 队列问题)
How do I access GUI (GTK) from multi threads?(如何从多线程访问 GUI (GTK)?)
multi-threading based RabbitMQ consumer(基于多线程的 RabbitMQ 消费者)
.NET#39;s Multi-threading vs Multi-processing: Awful Parallel.ForEach Performance(.NET 的多线程与多处理:糟糕的 Parallel.ForEach 性能)