In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "how to understand C# asynchronous delegation and multithreading". The content of the explanation is simple and clear, and it is easy to learn and understand. let's go deep into the editor's train of thought. Let's study and learn how to understand C# asynchronous delegation and multithreading.
On this issue, I think many beginners have as many questions as I do. What I said below may not be correct, I really hope that you can correct it here, because I am only talking about my own understanding.
In fact, asynchronous delegation has nothing to do with multithreading in C # programming. I have made a Sample, and I really don't see any statements like CreateThread written anywhere, but it can achieve the effect of asynchronousness. maybe the system hides the processing thread and is managed by the operating system, and does not want users to intervene too much, resulting in confusion.
Understanding of C # Asynchronous delegation
Here I would like to mention what delegation is, msdn seems to be a bit obscure, this does not blame them. I have a classmate who works as a translator at Microsoft, hehe. In fact, many translation jobs are not written by people who have been engaged in development for a long time, but by some college graduates or people who are good at English (with a smile, I used to translate msdn for my mentor when I was at vs 2005 beta, and I felt that the translation was better than that of Microsoft later). Ok, to get to the point, delegate is actually equal to the function pointer in C++, which is a variable pointing to the function address. I think, perhaps in order to be more object-oriented and avoid system errors caused by misuse of pointers, C # refers to the concept of delegation. In fact, whether it is an event or a delegate, everyone can think of them as the same thing as a class, they all need to be declared, they all need to be instantiated, and their instances can be regarded as objects of reference type. In this way, it is easier to understand a lot of things that feel very mysterious.
The delegate of a C # asynchronous delegate is to declare a "function pointer", but the "pointer" must declare the form in which it points to the function, that is, if I declare the delegate as:
Public delegate void BinaryDelegate (int startIndex, int count)
Then, this delegate can only point to a function that returns a value of void with arguments of int startIndex and int count, respectively.
Ok, is it possible to use delegates this way? Of course not, as mentioned earlier, C # is a pure object-oriented language, it must not have pointers, and I also said that in C #, like delegates or events, we can actually be regarded as variables of reference type. therefore, before use, instantiation must be instantiated, only instantiation can be called an object, otherwise it only puts forward a concept and cannot be applied in practice. For example, we put forward the concept of "human", but only by instantiating "human"-> "Zhang San" can this "Zhang San" be driven. For example, I asked Zhang San to carry water. I can't ask "human" to fetch water.
Application of C # Asynchronous delegation
BinaryDelegate addingDelegate = new BinaryDelegate (AddingFunction)
Note that the instantiated argument (equivalent to the constructor argument) can only be a function name, and this function name cannot take arguments (is it the same as C++ 's function pointer? ). Therefore, once the delegate is instantiated, there must be a function specified by the delegate in its scope (inside or outside the class), otherwise the compiler will make an error.
Thank you for your reading, the above is the content of "how to understand C# asynchronous delegation and multithreading". After the study of this article, I believe you have a deeper understanding of how to understand C# asynchronous delegation and multithreading. Specific use also needs to be verified by practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.