ulti threading is one of the most powerful concepts in programming. Using multithreading, you can break a complex task into multiple threads that execute independently of one another. One particularly good application of multithreading is in tasks that are synchronous in nature, such as Web services calls. By default, Web services calls are blocking callsthat is, the caller code will not continue until the Web service returns the result. But because Web services calls are often slow, this could result in sluggish client side performance unless you take special steps to make the call into an asynchronous one.
This article shows how to develop a charting application so you can see how to call Web services asynchronously without freezing the client UI. The sample code
uses the Chart FX component to display stock price information using a graph. For readers who would prefer a free charting library written in .NET, refer to the Related Resources section located in the left column of this article.
Creating the Web Service
The sample code needs access to a hypothetical Stock Quote Web service. To build the Web service using Visual Studio .NET 2003, create a new Web service project and name it "StockWS". This Web service consists of one Web method named getPrice()
, which accepts a single stock symbol parameter:
Public Function getPrice(ByVal stock As String) _
Return Rnd() * 100
method generates a random price regardless of the stock requested. Its sole purpose is to simulate a real Web service returning the price of a particular stock.
Although this article uses a made-up Web service for demonstration purposes, you can easily substitute a live Web service to display real stock information. Head over to http://www.xmethods.net
to see a list of stock Web services.