Click here to Skip to main content
15,794,275 members
Please Sign up or sign in to vote.
4.67/5 (3 votes)
See more:

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.

Updated 20-Jan-11 22:48pm
Sergey Alexandrovich Kryukov 21-Jan-11 17:09pm    
I appreciate your understanding that you need threading, which makes your question pretty good.

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.
Share this answer
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.
Share this answer
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.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900