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

waitHandle.WaitOne() not waiting for command.BeginExcecuteReader()

I am just learning to use asynchronous ADO commands and I would like to wait on the BeginExecuteReader() IAsyncResult wait handle.
When I use
Expand|Select|Wrap|Line Numbers
  1. WaitHandle waitHandle = asyncresult.AsyncWaitHandle;
  2. waitHandle.WaitOne();
  3.  
the main thread does not wait it just continues executing and eventually terminates killing the reader thread.

I my code is as follows
Expand|Select|Wrap|Line Numbers
  1.     static void Main( string[] args ) {
  2.  
  3.       dbRecordsHolder = new ArrayList();
  4.       SqlConnection connection = new SqlConnection( connectionString );
  5.       SqlCommand command = new SqlCommand( commandString, connection );
  6.  
  7.       connection.Open();
  8.       AsyncCallback callback = new AsyncCallback( DataReaderIsReady );
  9.       IAsyncResult asyncresult = command.BeginExecuteReader( callback, command );
  10.  
  11.       WaitHandle waitHandle = asyncresult.AsyncWaitHandle;
  12.       waitHandle.WaitOne();
  13.  
  14.       Console.WriteLine( "Done" );
  15.     }
  16.     private static void DataReaderIsReady( IAsyncResult result ) {
  17.       MessageBox.Show( "Results Load Complete", "I'm Done" );
  18.       SqlCommand command = (SqlCommand)result.AsyncState;
  19.       SqlDataReader sqlDr = command.EndExecuteReader( result );
  20.       if ( sqlDr.HasRows ) {
  21.         foreach ( DbDataRecord rec in sqlDr ) {
  22.           dbRecordsHolder.Add( rec );
  23.         }
  24.       }
  25.       Console.WriteLine( "Records Added" );
  26.       sqlDr.Close();
  27.       command.Connection.Dispose();
  28.     }
  29.   }
  30.  
  31.  
thank you for the help

john
May 26 '10 #1
0 1195

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

Similar topics

39
by: jabailo | last post by:
I am looping through a text file, and with each row, I launch a web service, asynchronously. Before I move on to the next step in the process, I want to make sure that all the web services have...
2
by: Pierre | last post by:
Hi, actually I have two short questions. 1.) I'm trying to find out if a waithandle is set. I use "handle.WaitOne(0, true);" which just waits for zero milliseconds. Is there a more formal way of...
2
by: Adrian | last post by:
hi I make the following call xmlResponse = xws.SubmitXml(Text, xmlRequest.DocumentElement, xmlFilter.DocumentElement) It returns what I want but I would like to do a "do while loop" while I...
2
by: Jon Paugh | last post by:
Hi, Can anyone explain the difference between the WaitOne vs. WaitAny methods on the IAsyncResult.AsyncWaitHandle object? They both wait for one, but the any seems to have different criteria...
1
by: Chad | last post by:
I am using SQL Server 2000. In Enterprise Mgr, under Management/Current Activity, I see a list SPIDs. I have a multi-tiered .NET web app that uses ADO.NET to connect to the database. Each time a...
0
by: Amir Shitrit | last post by:
Hi to all. What is difference between the methods found in the Monitor, Interlocked and WaitHandle classes in terms of performance? Is it true that Monitor.Wait uses the Interlocked class behind...
15
by: Peter Larsen [] | last post by:
Hi, I have a problem using a ManuelResetEvent in the GUI thread while receiving events from the Shell (new folders, rename etc). This is what i do: Receiving an event from the Shell....
0
by: Peter Duniho | last post by:
On Tue, 10 Jun 2008 03:41:27 -0700, Daniel Cuculescu <dcuculescu@ixiacom.comwrote: I admit, I wasn't even aware that _any_ message pumping was done when you're in a managed blocking call,...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
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
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
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...

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.