?
Solved

starting the thread immediatly

Posted on 2003-03-27
8
Medium Priority
?
251 Views
Last Modified: 2013-11-20
Hi everybody,
how can i make the UI thread start immediatly. My problem is when i call the thread class just before the main thread enters a loop, the new window of the thread loads up after the loop is over.
Thanks a million.
yossi
0
Comment
Question by:yossigordin
  • 2
  • 2
5 Comments
 
LVL 48

Expert Comment

by:AlexFM
ID: 8217050
Use Sleep with some small value after starting of new thread:

Create thread
Sleep(50);             // let other threads to work
start loop

0
 
LVL 31

Expert Comment

by:Zoppo
ID: 8217306
or use syncronization, i.e. with an event object:
create a event, after starting the thread in main-thread
wait for the event to be signaled. In new thread signal the
event when you want the main-thread to be continued.

this is 100% safe method while simply using a 'Sleep' cannot
grant that the sub-thread reached the wanted functionality.

ZOPPO
0
 
LVL 1

Author Comment

by:yossigordin
ID: 8223498
Hi,
can you elaborate?
I understood the concept , but i can't implement it correctly.
can you help?
yossigordin
0
 
LVL 31

Accepted Solution

by:
Zoppo earned 400 total points
ID: 8223627
Well, here's ome untested pseudo-code:

HANDLE hEvent = NULL;

...
if ( NULL == hEvent )
 hEvent = ::CreateEvent( NULL, FALSE, FALSE, NULL );
...
// create your thread here
AfxBeginThread(...);

// now we wait until the event is signalled
::WaitForSingleObject( hEvent, INFINITE );

// now here we can continue
...


Then, in the thread you simply need to find a point where
you know it's ok that the main thread continues and there call

::SetEvent( hEvent ); // waiting main-thread is resumed


ZOPPO
0
 
LVL 1

Author Comment

by:yossigordin
ID: 8278156
Hi,
10nxs a lot for everything, but i manged to work it out without threads.
yossigordin
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses

621 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question