473,410 Members | 1,952 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,410 software developers and data experts.

How can I turn this code snippet into a blocking function?

How can I rewrite 'getSpecialData()' more so that it more elegantly waits
for the handler to complete?

- Jamie

class someClass {
private class SpecialData { ... }
private SpecialData specialData;
private bool blocking;

private void retrievedHandler(SpecialData d)
{ specialData = d; blocking = false; }

public SpecialData getSpecialData()
{
Retriever rtvr = new Retriever(new
DataRetrievedHandler(retrievedHandler));
blocking = true;
rtvr.fetch();
while(blocking) {}
return this.specialData;
}
}
Sep 27 '07 #1
2 1114

"Jamie Risk" <ri**@intectus.comwrote in message
news:eP****************@TK2MSFTNGP05.phx.gbl...
How can I rewrite 'getSpecialData()' more so that it more elegantly waits
for the handler to complete?

- Jamie
class someClass
{
private class SpecialData { ... }
private SpecialData specialData;

private ManualResetEvent m_event = new ManualResetEvent( false );

private void retrievedHandler(SpecialData d)
{
specialData = d;
m_event.Set();
}

public SpecialData getSpecialData()
{
Retriever rtvr = new Retriever(
new DataRetrievedHandler(retrievedHandler));

m_event.Reset();
rtvr.fetch();
m_event.WaitOne();

return this.specialData;
}
}
Sep 27 '07 #2
Hello Jamie,
How can I rewrite 'getSpecialData()' more so that it more elegantly
waits for the handler to complete?

- Jamie

class someClass {
private class SpecialData { ... }
private SpecialData specialData;
private bool blocking;
private void retrievedHandler(SpecialData d)
{ specialData = d; blocking = false; }
public SpecialData getSpecialData()
{
Retriever rtvr = new Retriever(new
DataRetrievedHandler(retrievedHandler));
blocking = true;
rtvr.fetch();
while(blocking) {}
return this.specialData;
}
}
Just wondering... Why? If you're offloading processing to another thread,
why block the one you're currently in... It doesn't make sense to me. Why
not just retrieve the data synchronously. It would be much easier and in
the end you'll get the same result.

--
Jesse Houwing
jesse.houwing at sogeti.nl
Sep 27 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Phil Powell | last post by:
I borrowed this code from a source: for($a=0;$a<imagecolorstotal ($image_id);$a++) { $color = imageColorsForIndex($image_id,$i); $R=.299 * ($color)+ .587 * ($color)+ .114 * ($color);...
1
by: Hal | last post by:
I am experiencing blocking problems on SQL Server 2000, SP3a. I have read the posts and set up a job SQL agent to report on these occurences I save the results to a table before executing an sp to...
43
by: dan baker | last post by:
I have a page that gets loaded with a meta-refresh hardcoded so that a few things on the page get updated. its kind of a fake chat board. anyway, what I need to do is turn off the meta-refresh once...
9
by: Koo | last post by:
How do you create your own blocking function? Koo
23
by: David McCulloch | last post by:
QUESTION-1: How can I detect if Norton Internet Security is blocking pop-ups? QUESTION-2a: How could I know if a particular JavaScript function has been declared? QUESTION-2b: How could I...
3
by: Trishia Rose | last post by:
Hi, I understand how to operate non-blocking send and recv in C, so as to exchange data with multiple connections without blocking with every function call. My question is, how to set up a...
18
by: Joe Fallon | last post by:
I have some complex logic which is fairly simply to build up into a string. I needed a way to Eval this string and return a Boolean result. This code works fine to achieve that goal. My...
3
by: Jamie Risk | last post by:
I'm attempting to improve some serially executing code (that uses the SerialPort class) bogging Windows down when it runs. To do the 'antibogging' I'm following the example from MSDN...
3
by: Hardy | last post by:
I created a code snippet which is for displaying file name,Line number and function name in C#.NET project. // <File> sf.GetFileName() // </File> // <Line> sf.GetFileLineNumber().ToString()...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.