加载状态显示 [英] Loading status display

查看:105
本文介绍了加载状态显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在开发一个应用程序.在我的应用程序中,单击按钮时,将从网站上获取一些数据,并在我的对话框中显示这些数据(使用Microsoft WebBrowser控件).
这似乎要花费很多时间,因此我想在完成该过程之前显示状态文本.我更喜欢使用事件同步来进行线程化.
请帮帮我.


谢谢,
Laje

解决方案

最好使用线程而不是异步API(但是,可以将它们组合).

可能有几种不同的方法.

以我的经验,最有效的方法是:
1)您应该避免一遍又一遍地创建和清理线程(例如单击按钮).
2)您使用的每个网站仅创建一个线程.如果要使用N个不同的站点-N个线程.
3)从头开始创建所有线程,并在显示GUI时启动它们.
4)在每个线程中都使用事件等待句柄来防止线程处于空闲状态,可以通过自动重置来创建(可以使用不同的方法;使用手动重置选项时,您将需要手动重置).
5)与每个线程共享表示任务的数据,并在关键部分提供线程安全性.
6)当您要为线程设置新任务时,请填写任务数据(请参见上面的项目)并设置线程的事件句柄-它将使线程运行.
7)当线程完成下一个任务时,需要通知GUI;如果数据进入Web浏览器控件,则可以间接通知它-加载页面时它具有事件通知-提供事件处理程序.最终,您的GUI应该以状态显示作为响应.
8)最后,您可能需要处理一系列的任务(我不确定您的应用程序是否适合),然后您需要一个具有同步功能的队列.

许多实现细节取决于您使用的是哪个库,尤其是对于GUI(您没有共享此信息).因此,如果您需要更多详细信息,请首先提供有关代码的更多详细信息-如果可以的话,我会回答.


由于许多人提出了暴露相关问题的问题,因此我开始提出小技巧形式的提示/技巧"部分的一些食谱.

请在这里查看我的微型作品:
用于线程通信和线程间调用的简单阻塞队列 [ ^ ].

我认为这将为您提供一个有用的想法,尤其是如果您在示例代码中查看线程包装器.到文件或内存,然后在完成后将Web控件指向您的本地副本.它会在存在网络延迟的情况下加载而不显示任何空白框.


Hi,

I am developing an application. In my application, when clicking a button, some data is fetched from a website and the is shown on my dialog (using Microsoft WebBrowser control).
This seems to be taking so much time, so I would like to dispaly a status text until the process is done. I prefer to do it with Threading, using event synchronisation.
Please help me.


Thanks,
Laje

解决方案

It''s good that you prefer threading instead of asynchronous APIs (however, you could combine them).

There could be few different approaches.

In my experience most robust approach is this:
1) You should avoid creating and cleaning up a thread over and over on each task (like a button click).
2) Create just one thread per Web site you work with. If you want to work with N different sites -- N threads.
3) Created all threads from the very beginning and start them when your GUI is shown.
4) Keep your threads from idle run using event wait handle in each, can be created with auto-reset (you can use different approached; with manual reset option you will need to reset manually).
5) Have shared data representing a task with each thread, provide thread safety with Critical Section.
6) When you want to set a new task for a thread, fill in task data (see the above item) and set thread''s event handle -- it will make thread running.
7) When next task is done by the thread, it needs to notify GUI; it could be notified indirectly if data goes to the Web browser control -- it has event notification when the page is loaded -- supply an event handler. Ultimately, you GUI should respond with status display.
8) Finally, you may want to work with a queue of tasks (I''m not sure adequate for your application), then you need a queue with synchronization.

Many implementation detail depends on what library you''re using, especially for GUI (you did not share this information). So, if you need more detail, first provide more detail on your code -- I''ll answer if I can.


As many people ask Questions exposing related problems, I started to put some recipes to Tips/Tricks section in the form of small articles.

Please take a look an my miniature work here:
Simple Blocking Queue for Thread Communication and Inter-thread Invocation[^].

I think it will give you a useful idea, especially if you look at Thread wrappers in sample code.


maybe, you can use some simaler function to wget in a background thread to save the data to a file or memory, then when complete point the web control to your local copy. it should load in without showing an empty box while there is network delay.


这篇关于加载状态显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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