Use. NET multithread technology display real time stock information

Source: Internet
Author: User

The content of this article is to learn how to build an application using multithreaded technology, so that the user interface (UI) is still active while the application is performing time and resource-intensive background transactions.

Multithreading Technology (multithreading) is one of the most powerful concepts in programming. With multithreading, you can split complex transactions into multiple threads that are executed independently of each other. A good multithreaded application is naturally synchronized, similar to a Web service invocation. By default, a Web service invocation belongs to a blocking (blocking) call-that is, the caller (caller) code stops executing until the Web service returns the result. However, because Web service calls are usually slow, it can cause client performance to degrade unless you take extraordinary steps to make the call asynchronous.

This article explains how to build a chart application, from which you can see how to invoke the Web service asynchronously without impacting the client UI. The sample code uses the Chart FX component to display stock information using graphics. Of course, readers can also use. NET write a free chart class library.

Set up a Web service

The sample code needs access to the hypothetical stock quote Web service. We set up a Web service in Visual Studio. NET 2003 and named it "Stockws." This Web service consists of a Web method called GetPrice () that accepts only one stock encoding parameter:

Public Function GetPrice (ByVal-as String) as single
return Rnd () * 100
End Function

Regardless of what the requested stock is, the GetPrice () method generates a random price. Its only goal is to simulate a real web service that returns a specific stock price.
Although this article uses a molded Web service to demonstrate, you can easily replace the Web service to display real stock information.

displaying graphics using the Chart FX component

After you have established the Web service project above, add a Windows Application project to the solution browser (called the stock Quote, the ticker quote). Add a reference to the project to the Web service you established earlier. The solution browser should now be shown in Figure 1.


Figure 1: The project in Solution Explorer-the figure shows the STOCKWS Web service project and

Windows Forms project Stock Quote

To build the sample project for this article, you must download and install the Chart FX component 30-day trial from http://chartfx.com/. After you install the drawing component, you can see it in the visual Studio. NET 2003 Tool box (shown in Figure 2).


Figure 2: The Chart Component in the tool box-you will need to download and install the Chart FX component 30-day trial from the website.

In the default Form1 for this Windows application, populate the form with some of the following controls, as shown in Figure 3:

· Chart
· ComboBox
· Button


Figure 3:stock Quote main form-The figure shows the form style after adding the appropriate control.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.