IT Community - Software Programming, Web Development and Technical Support

How to wait a program control until a thread completes it process?

This is a discussion on How to wait a program control until a thread completes it process? within the C# Programming forums, part of the Software Development category; Hi, I am have started a thread from the main class. After starting the thread, the program control comes to ...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Software Development > C# Programming

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 11-04-2007, 11:52 PM
$enthil $enthil is offline
D-Web Sr.Programmer
 
Join Date: Apr 2007
Posts: 162
$enthil is on a distinguished road
Cool How to wait a program control until a thread completes it process?

Hi,

I am have started a thread from the main class. After starting the thread, the program control comes to the next statement and have to wait in that statement until the thread completes it process..
__________________
$enthil

Last edited by $enthil : 11-14-2007 at 09:58 PM.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 11-14-2007, 10:01 PM
it.wily it.wily is offline
D-Web Programmer
 
Join Date: Jul 2007
Posts: 89
it.wily is on a distinguished road
Smile Re: How to wait a program control until a thread completes it process?

Try waithandler()

This is used to wait the program control until a thread finishes its process...
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 11-14-2007, 10:03 PM
$enthil $enthil is offline
D-Web Sr.Programmer
 
Join Date: Apr 2007
Posts: 162
$enthil is on a distinguished road
Question Re: How to wait a program control until a thread completes it process?

Can you give me some sample code describing this?
__________________
$enthil
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 11-16-2007, 02:45 AM
it.wily it.wily is offline
D-Web Programmer
 
Join Date: Jul 2007
Posts: 89
it.wily is on a distinguished road
Smile Re: How to wait a program control until a thread completes it process?

Try this code...

Quote:
class TwoWaySignaling
{
static EventWaitHandle ready = new AutoResetEvent (false);
static EventWaitHandle go = new AutoResetEvent (false);

static volatile string message; // We must either use volatile
// or lock around this field
static void Main()
{
new Thread (Work).Start();

ready.WaitOne(); // First wait until worker is ready
message = "ooo";
go.Set(); // Tell worker to go!

ready.WaitOne();
message = "ahhh"; // Give the worker another message
go.Set();

ready.WaitOne();
message = null; // Signal the worker to exit
go.Set();
}

static void Work()
{
while (true)
{
ready.Set(); // Indicate that we're ready
go.WaitOne(); // Wait to be kicked off...
if (message == null) return; // Gracefully exit
Console.WriteLine (message);
}
}
}
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 11-16-2007, 03:08 AM
$enthil $enthil is offline
D-Web Sr.Programmer
 
Join Date: Apr 2007
Posts: 162
$enthil is on a distinguished road
Smile Re: How to wait a program control until a thread completes it process?

yes.. the code works fine... thanks...
__________________
$enthil
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Describe the difference between a Thread and a Process? vadivelanvaidyanathan ASP and ASP.NET Programming 7 12-25-2008 04:57 AM
Process & Thread Sathish Kumar C# Programming 4 08-22-2007 04:47 AM
How to get a reference to primary thread from process ? theone Mobile Software Development 1 07-30-2007 03:50 AM
Describe the difference between a Thread and a Process? kingmaker C# Programming 1 07-30-2007 12:21 AM
How to launch Real Player program through my j2me midlet program? itbarota J2ME 1 07-25-2007 11:39 PM


All times are GMT -7. The time now is 10:40 PM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.

SEO by vBSEO 3.0.0