Make Main Thread sleep [modified]
-
Hello Friends, Is there any way we can make the main thread sleep from within the another user created theread. I am using the code like below
void fun(void)
{
...
...if(Some Condition)
{
CreateThread(0, 0, ( LPTHREAD_START_ROUTINE ) ThreadProc, 0, 0, 0 );
//I want to show some dialog continuously and also the same function (fun) to be running.
//And So I am using the Thread to call the Function (fun()
)
DialogBox(...); //
}
if (Some Other condition)
{
** //Here I want the main thread to sleep for some time**
}}
void ThreadProc(void)
{fun();
}
-- modified at 6:01 Wednesday 17th October, 2007
[ Screen Capture ][ Tool Tip ]
-
Hello Friends, Is there any way we can make the main thread sleep from within the another user created theread. I am using the code like below
void fun(void)
{
...
...if(Some Condition)
{
CreateThread(0, 0, ( LPTHREAD_START_ROUTINE ) ThreadProc, 0, 0, 0 );
//I want to show some dialog continuously and also the same function (fun) to be running.
//And So I am using the Thread to call the Function (fun()
)
DialogBox(...); //
}
if (Some Other condition)
{
** //Here I want the main thread to sleep for some time**
}}
void ThreadProc(void)
{fun();
}
-- modified at 6:01 Wednesday 17th October, 2007
[ Screen Capture ][ Tool Tip ]
GauranG33 wrote:
from within the another user created theread
WTF are you trying to say here ?! :omg:
[VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]
-
Hello Friends, Is there any way we can make the main thread sleep from within the another user created theread. I am using the code like below
void fun(void)
{
...
...if(Some Condition)
{
CreateThread(0, 0, ( LPTHREAD_START_ROUTINE ) ThreadProc, 0, 0, 0 );
//I want to show some dialog continuously and also the same function (fun) to be running.
//And So I am using the Thread to call the Function (fun()
)
DialogBox(...); //
}
if (Some Other condition)
{
** //Here I want the main thread to sleep for some time**
}}
void ThreadProc(void)
{fun();
}
-- modified at 6:01 Wednesday 17th October, 2007
[ Screen Capture ][ Tool Tip ]
that depends on the design and implementation of both of your threads. and also, the context, where the sleep is required matters. can you share them with us? ----------------------------------------------------------
Suggestion to the members: prefix your main thread subject with [SOLVED] if it is solved. chandu.
-
GauranG33 wrote:
from within the another user created theread
WTF are you trying to say here ?! :omg:
[VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]
Now I hav modified the Question. and Put some Example code.
[ Screen Capture ][ Tool Tip ]
-
Hello Friends, Is there any way we can make the main thread sleep from within the another user created theread. I am using the code like below
void fun(void)
{
...
...if(Some Condition)
{
CreateThread(0, 0, ( LPTHREAD_START_ROUTINE ) ThreadProc, 0, 0, 0 );
//I want to show some dialog continuously and also the same function (fun) to be running.
//And So I am using the Thread to call the Function (fun()
)
DialogBox(...); //
}
if (Some Other condition)
{
** //Here I want the main thread to sleep for some time**
}}
void ThreadProc(void)
{fun();
}
-- modified at 6:01 Wednesday 17th October, 2007
[ Screen Capture ][ Tool Tip ]
-
GauranG33 wrote:
from within the another user created theread
WTF are you trying to say here ?! :omg:
[VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]
toxcct wrote:
WTF are you trying to say here ?!
Don't Know [:)]
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
Never mind - my own stupidity is the source of every "problem" - Mixturecheers, Alok Gupta VC Forum Q&A :- I/IV Support CRY- Child Relief and You
-
Hello Friends, Is there any way we can make the main thread sleep from within the another user created theread. I am using the code like below
void fun(void)
{
...
...if(Some Condition)
{
CreateThread(0, 0, ( LPTHREAD_START_ROUTINE ) ThreadProc, 0, 0, 0 );
//I want to show some dialog continuously and also the same function (fun) to be running.
//And So I am using the Thread to call the Function (fun()
)
DialogBox(...); //
}
if (Some Other condition)
{
** //Here I want the main thread to sleep for some time**
}}
void ThreadProc(void)
{fun();
}
-- modified at 6:01 Wednesday 17th October, 2007
[ Screen Capture ][ Tool Tip ]
Why you want to make Main Thread Sleep..? this is not good design. as in Sleep State main thread will process nothing. you should change you design to make MianThread do nothing instead of making it sleep.
GauranG33 wrote:
void ThreadProc(void){ fun();}
this will make your worker thread sleep not main thread. as function call is from worker thread not main thread
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
Never mind - my own stupidity is the source of every "problem" - Mixturecheers, Alok Gupta VC Forum Q&A :- I/IV Support CRY- Child Relief and You
-
it seems that, you are landing in some sort of recursion here. BTW, i understood that, you want to do some application, which keeps a dialog displayed until you stop it. am i right? if so, then i can guide you better.
actully I want to display the Dialog Box Continously untill some events happen and also want that my application run in the background and so i am using the thread.
[ Screen Capture ][ Tool Tip ]
-
actully I want to display the Dialog Box Continously untill some events happen and also want that my application run in the background and so i am using the thread.
[ Screen Capture ][ Tool Tip ]
-
actully I want to display the Dialog Box Continously untill some events happen and also want that my application run in the background and so i am using the thread.
[ Screen Capture ][ Tool Tip ]
thats what i meant. i have one active X control made by me to achieve your task. if you want, i can share it with u. you have to use it as follows. your main thread { control.start(); //your code which u call as ur background code here ........ ........ //control.stop(); } here, from ur start to stop function, the dialog will be displayed.
-
actully I want to display the Dialog Box Continously untill some events happen and also want that my application run in the background and so i am using the thread.
[ Screen Capture ][ Tool Tip ]
GauranG33 wrote:
actully I want to display the Dialog Box Continously untill some events happen and also want that my application run in the background and so i am using the thread.
call a model dialog box.. it block the main thread, and you thread will continue to run in background
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
Never mind - my own stupidity is the source of every "problem" - Mixturecheers, Alok Gupta VC Forum Q&A :- I/IV Support CRY- Child Relief and You
-
Have the main thread create and display a modeless dialog box. This way the box is displayed but the main thread can keep working. Judy
yes it displays the modeless dialog
[ Screen Capture ][ Tool Tip ]
-
yes it displays the modeless dialog
[ Screen Capture ][ Tool Tip ]
That wasn't what I meant. I was addressing your statement from the initial post: CreateThread(0, 0, ( LPTHREAD_START_ROUTINE ) ThreadProc, 0, 0, 0 ); //I want to show some dialog continuously and also the same function (fun) to be running. //And So I am using the Thread to call the Function (fun() ) DialogBox(...); // To accomplish this, consider displaying a modeless dialog box and just directly calling the function. This may not be appropriate for your program - it depends on what the function actually does, but you didn't provide enough information. Judy
-
yes it displays the modeless dialog
[ Screen Capture ][ Tool Tip ]
-
Hello Friends, Is there any way we can make the main thread sleep from within the another user created theread. I am using the code like below
void fun(void)
{
...
...if(Some Condition)
{
CreateThread(0, 0, ( LPTHREAD_START_ROUTINE ) ThreadProc, 0, 0, 0 );
//I want to show some dialog continuously and also the same function (fun) to be running.
//And So I am using the Thread to call the Function (fun()
)
DialogBox(...); //
}
if (Some Other condition)
{
** //Here I want the main thread to sleep for some time**
}}
void ThreadProc(void)
{fun();
}
-- modified at 6:01 Wednesday 17th October, 2007
[ Screen Capture ][ Tool Tip ]
GauranG33 wrote:
//Here I want the main thread to sleep for some time
Bad idea.
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
-
yes it displays the modeless dialog
[ Screen Capture ][ Tool Tip ]
then display model dialog.. is there is any problem..
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
Never mind - my own stupidity is the source of every "problem" - Mixturecheers, Alok Gupta VC Forum Q&A :- I/IV Support CRY- Child Relief and You