473,406 Members | 2,633 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Blocking a thread

Hi,

I'm new with programming and I have a question relating thread. Please look at the following example:

....
thread = new Thread(new ThreadStart(Open));
thread.Start();
....

private void Open()
{
try
{
while (true)
{
receiver = new StreamReader(client.GetStream());
input = receiver.ReadLine();
......

I noticed that the thread is paused (or blocked) until "receiver" receive data. Now my question is how to replicates this behavior?
Example:

int DoSomething()
{
int result = 0;
// do something here
return result;
}

void ThreadFunction
{
while(true)
{
// process here
int b = DoSomething() <-- i want the thread to "stop" here until there is actually something to do
// process here some more
}
}

Thanks in advance.
Sep 11 '08 #1
3 1056
pootle
68
Check out System.Threading.WaitHandle.WaitOne. Is this the behaviour you need? Check out MSDN for sample code.

HTH
Sep 11 '08 #2
joedeene
583 512MB
Hi,

I'm new with programming and I have a question relating thread. Please look at the following example:

....
thread = new Thread(new ThreadStart(Open));
thread.Start();
....

private void Open()
{
try
{
while (true)
{
receiver = new StreamReader(client.GetStream());
input = receiver.ReadLine();
......

I noticed that the thread is paused (or blocked) until "receiver" receive data. Now my question is how to replicates this behavior?
Example:

int DoSomething()
{
int result = 0;
// do something here
return result;
}

void ThreadFunction
{
while(true)
{
// process here
int b = DoSomething() <-- i want the thread to "stop" here until there is actually something to do
// process here some more
}
}

Thanks in advance.
also please use code<#> tags for the code, to make it easier for members/experts to assist you with your development problems.

joedeene
Sep 11 '08 #3
Thanks for the link pootle, it is what I'm looking for. And sorry for the missing code tags joedeene.
Sep 12 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: David Sworder | last post by:
This message was already cross-posted to C# and ADO.NET, but I forgot to post to this "general" group... sorry about that. It just occured to me after my first post that the "general" group readers...
2
by: Bruce Vander Werf | last post by:
How can I cleanly stop a thread that is currently blocking on Socket.Receive? I don't want to use Thread.Abort, because I would like the thread method to exit cleanly, and the same code must run...
3
by: Logan McKinley | last post by:
I have a C# program that uses blocking sockets and want to allow the user to stop the server. The problem I am having is the socket blocks on...
7
by: David Sworder | last post by:
Hi, I'm developing an application that will support several thousand simultaneous connections on the server-side. I'm trying to maximize throughput. The client (WinForms) and server communicate...
4
by: Anthony Boudouvas | last post by:
Hi to all, i have a form with 2 System.Windows.Forms.Timer objects. One fire every 5 seconds and the other every 10 seconds, the both take actions in two hashtables declared in same form. ...
2
by: Rene | last post by:
Hi, In my VB6 application I'm using a class/object that is using full-async ADO. I can start multiple queries, the class stores the ADODB.Recordset object in an array and waits for the...
6
by: roger beniot | last post by:
I have a program that launches multiple threads with a ThreadStart method like the following (using System.Net.Sockets.Socket for UDP packet transfers to a server): ThreadStart pseudo code: ...
6
by: Joe HM | last post by:
Hello - I have a function that calls Thread.Abort() to stop a thread in a _Closed() Method of a GUI. The thread contains a blocking call on a TCP socket and that is the easiest way to stop...
3
by: Bob | last post by:
Hi, I have an app that has a 3rd party phone answering control (4 of ) (interfacing with dialogic 4 line card) attached to the main form. each control raises an event when its Dialogic line...
12
by: puzzlecracker | last post by:
is it even possible or/and there is a better alternative to accept input in a nonblocking manner?
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.