Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VC8.0
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
Posted 20-Jan-11 22:17pm
Edited 20-Jan-11 22:48pm
CPallini325.7K
v5
Comments
SAKryukov at 21-Jan-11 17:09pm
   
I appreciate your understanding that you need threading, which makes your question pretty good.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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.
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

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.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  

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



Advertise | Privacy | Mobile
Web04 | 2.8.1411022.1 | Last Updated 23 Jan 2011
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100