?
Solved

starting the thread immediatly

Posted on 2003-03-27
8
Medium Priority
?
245 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
8 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

762 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