Presenter:Mike Taulty
In this session we'll look at how we can submit work to the database asynchronously in ADO.NET 2.0.
The following text is a software generated transcript of the video. Click on a minute link to jump to a location within the video
Minute 0
Hello and welcome to the sequel server 2005 at its session will try and spend is five to 10 minutes looking at a key developer features it was an excellent five minus I told him I work in the developer and platform group in the UK and in this particular session which is less than five ministers are looking at how we can perform asynchronous operations from 80 net two against a Conservative thousand five to its quite a common requirement that time something like client has a user interface and would stay responsive whilst it s sending data operations to something like a signals at the data growth and 80 net 2 0 has great features for doing work asynchronously so essentially in the background and not on the main thread of the application so that we can continue to do something else such as perhaps process user interface messages and keep that user interface responsive on the screen to look at how that works
Minute 1
Okay so here I m working with the Conservative thousand five beta two and visual studio 2005 beta one refresh and have built a simple Windows application which shows how we can send commands asynchronously to the database so as they cook and an application soberly easy thing to do is to begin by just running the application saw runners in the debugger and is very simple at all happen seriously have a perform and we have a button which doesn t get some data from the database and we have a timer over here which will constantly update this label as the going getting that data from the database such as resizes so we can move the former and onscreen a little bit so that it will quickly get data but what you should season while Ross getting the data argue I remains responsive and time it takes and we get label updated
Minute 2
And then the data comes back and displayed onscreen servility that another time to quit the get data button to take the time it takes the label against the former still responsive and the data comes back on screen and the reason why Mr responsive and we cannot go that time ears because we are run working with asynchronous commands in the background to a cyclical of the code looks like this is if we wanted to go to the form is a couple of interesting things in here but essentially it s pretty simple to program it is to make this work so the first thing to point out is that the using standard connection to the database with the exception that weaves in the connection strain write downs switched on on asynchronous processing if you don t do that you are guilty of the asynchronous crimes against the database you ve got to sell and connection string as it stands right now you can see the
Minute 3
On something like a connection crassly have new methods on here like then we did notice in asynchronous version of opening a connection to the database so that will be in a simplest way of getting the collection and actually following the net than and there will also be an end open which will do the same thing as you would expect what completely the open call to the database when it happened asynchronously using asynchronous connections here though it is in what we re doing is we are creating a sequel server commands a great amount and you see that I ve actually explicitly damage my own performance here because the first thing I do in this man is a distillate five seconds so if I will always take five seconds longer than it should do only to select the entire affair set of data from the customer s table and North went to and created all we do here is command begin execute reader I noticed that on commands as a whole
Minute 4
Interview begin and asynchronous operations like execute on query and execute XML reader but he what we do is we begin execute reader and was so then we asynchronously got an excuse can and I will get called back in this court that routine at the point where the data is ready to be read back of the wires will have gone across sequel got the results are coming back to us and they got again then get notified to call back and you can see that in the callback function down here this is standard a sink begin and end pattern in net we end the execution of the reader giving it the asynchronous cell that we got when he didn t begin and the other is that the data reader and from there then we just asynchronous programming in order to get that reader am into a dataset and get it back on screen and refreshed it important
Minute 5
Odourless callback will happen on a different thread and the user interface thread so we need to do the right thing with respect and Windows forms in threading which we do here with the invoke function that is really nothing to do with them in a single operation itself on the database so really all we do is reset a secret process into true begin execute reader in this case we read after callback we could also just am get the racing results and weights have nothing to occur but it means that we can continue processing Windows messages whilst the data is going off the database so that s pretty much it has all utility program asynchronously earned execute commands a synchronously radio net two against the facilities as far so overseen in this session will radio net 2 0 we have ways of operating asynchronously against the database with an open connection is asynchronously begin execute commands a synchronously
Minute 6
And even get back readers and so on asynchronously against the database programming model fits in just standard would net so we have begin operations were reduced to just have the operations themselves present on things like connection glasses and command glasses and it will allow us to do things like building a nice response of July which stays on the screen is updatable whilst we re going off and the working of the database server and it s important to note that the underlying implementation of this is not a mechanism such as going off and creating a separate background is read in order to be able to do the asynchronous I O is that she implemented by the age net programming model are using real asynchronous network I O under the covers some are really doing proper windows facing KO here in order to get the results back from sequence so we should get decent performance from what we do with a sink I O and 80 net 2 0
Minute 7
So where can you go if you want to get more information on six and 2005 others the MSDN developer Centre MSDN Microsoft com sequel is a great vertigo there s a whole wealth of information over the developer around to Conservatives as five if you haven t already got yourself a copy of sequence over 2005 strongly recommend that you go and get a lease the express edition around again the URL is there on the screen or if you re an MSDN subscriber you can use your subscriber downloads to get a full edition of facilities as in five in beta form as it is right now if there s anything it is like to get more information on from this particular session their feel free to send me e mail my e mail address is on the screen there and then told the Microsoft com that is very much listening session and hope to see you next time
Click here to go to original video page
Thursday, July 24, 2008
Video: Using asynchronous commands in ADO.NET 2.0
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment