Questions about the parameters and return values of threads

Source: Internet
Author: User

Creating a new thread for a process is a simple question, but there are some important issues to emphasize, such as when running a new thread, the method or procedure that runs with the AddressOf operation does not have annotations and parameters, and cannot return a value, in order to solve this problem, There are several simpler ways to set parameters on a thread and return a value from the process of a separate thread.
1. Set parameters for newly established threads
Because when a new thread class is created, only one AddressOf operation is used, so that there is no indication that a thread is about to run independently.
One way to set a parameter for a thread is to use a global variable, which allows the user to distinguish between some of the parameters and comments used by the thread. There are some drawbacks, however, because global variables can be difficult when the user is debugging a program, and it is difficult to maintain code, and things can become complicated when you copy a procedure from multiple independent threads.
The best way to do this is to set the values of the properties of a new thread that need to be set on the method in the free thread. The advantage of this is that each time a user creates a new thread object, the object can have its own property value, that is, it can have its own parameters.

2. Return parameters from the free thread process
Because when a user runs a separate thread, it can only be a procedure in a thread, not a function, or a byref reference, so the user must use some other technique to get the information they need from the thread to their program. The easiest way to do this is by setting the global variable, when a thread ends, it assigns a value to a global variable, however, as this method should be avoided, and if this is done, the user must first determine whether the thread is over before accessing the global variables. Undoubtedly reduces the efficiency and accuracy of the program.
The best way to return a value from a thread is to create an event with the value that needs to be returned as a parameter, and you can get the return value you want by executing the event. If the event is running and the user needs a return value that is a global variable, you can simply set the event to return a global variable. When the thread is finished, the main program can take advantage of the values returned by those events to take the next step.

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.