Home > Net >  Questions about the Task
Questions about the Task

Time:05-11

Suppose I have a method that is the case, of course, may be my grammar is wrong
 
Public async void the Run () {
Var RST=await (XXX);
Var rst2=(XXX);
}

Why want to use the first rather than the second, well, asynchronous, but I know that for interface, each request is asynchronous, why even inside the method using asynchronous?
I think this is for the sake of asynchronous induction,
If is parallel I can understand, wait several method performs complete go down again! It can improve the efficiency of execution,
I haven't had enough to understand the Task should be! Hope the great god give a popular hui to parse, thank!!!!!!

CodePudding user response:

My is the interface refers to the WCF, webapi... This kind of interface!

CodePudding user response:

What is await, await is waiting, waiting for the results,

So we don't care about you is what WCF, webapi,

We only care about you want to perform as a result, don't want the result is the second, you want to the results
you are the first one
Yes, a year ago that a few new to tell you that 5 years want results, put a timer, loop, add a variable, this is a standard answer

And a year later, let their own answer, or standard answer?

CodePudding user response:

I am the second can also returns the result

CodePudding user response:

Await is
If XXX is an asynchronous method,
Var ss=await (XXX) is asynchronous waiting for the results returned,
XXX (); Is executed asynchronously, regardless of the return results
Var ss=(XXX). The Result is synchronous get return Result,

For example:
Public void Method1 () {
Print log 11
An ()
Print log 22
}

Public async void an () {
Code 1
Print log 33
Await (XXX);//XXX () more time-consuming Task available. The Delay () instead of test
Print log 44
Code section 2
Print log 55
}
Log order for 11 22 33 44 55, that is an execution of the code segment 1 is returned to the first


Suggested that baidu.net awai mechanism

CodePudding user response:

 
Public async Task ExcuteSql () {
//insert data
return true;
}
Public bool ExcuteSql_2 () {
//insert data
return true;
}
Public async void InsertData () {
Var RST=await ExcuteSql ();
Var rst2=ExcuteSql_2 ();
}

CodePudding user response:

reference 1/f, hands on the keyboard to knock very light response:
I interface refers to the WCF, webapi... This kind of interface!


The interface has something to do with your problem? It doesn't matter, don't make contact, it is, you can say you are iis, iis every visit is independent thread,
Independent thread with asynchronous?? Threads are threads, asynchronous is asynchronous, or that sentence watch less blog garden, thread and asynchronous itself is two independent concepts,

Concurrent threads are CPU, single-threaded and multithreading is a set of concepts
Asynchronous IO is -- -- -- -- -- -- -- -- synchronous I/o and asynchronous I/o is the concept of a set of

So, how was your WCF, webapi how, there is discussion topic 1 cent relationship with you, don't learn blog garden that relations of trying, do you want to climb relationship, please prepare a murder case to discuss the String is very simple, why the blog garden all day long with a String, because they like to put a variety of terms and concepts relations,

Yes, if you think that WCF is asynchronous, ok, you can not await, so if the Run you need to perform 5 seconds, then he is executed for 5 seconds, if there is a string, in the Run ok, the 5 second string does not release, because you are in use, so they began to disorderly relations, string let I crashed, we said is not string to make your system crashes, you are writing to let you system crash

Await (XXX) is another thing, he back to split into smaller execution unit, these smaller execution unit, will take you 5 seconds, into N smaller execution unit, assume that it takes one string unit as long as one second, he completed a string no, can you guess what the blog garden that there are no favorite pot string??

CodePudding user response:

The
reference 7 floor hands on the keyboard to knock very light response:
may I just have no description is clear, as above, I do the same thing with ExcuteSql2 ExcuteSql, why write asynchronous?


We say that the asynchronous and synchronous is a set of concepts,

So you ask us why asynchronous, so we have to ask, do you want to sync?? "Is the concept of asynchronous I let other people do, ready to let me know, and I can also do other things to do during this time,"
Synchronization means "I let others do, but now I'm waiting for him to finish, this time I don't do anything, stood staring at him behind his back,"

Iis, WCF is multithreaded, can the parallel access, but he in parallel, you no matter??????? No matter, no matter, then please click blog to the garden to discuss the "attack"

CodePudding user response:

https://www.cnblogs.com/huangxincheng/p/14743654.html

OK, are you ready to see blog garden, just those who like disorderly relations of killings, just this murder case is a year ago that a few new give you 5 years standard answer, just like there is a disorderly relations blogger

Ready, please, don't want to put the thread and asynchronous disorderly relations together with the results of the

"Threads is asynchronous, so please open a thread, and then put the timing, put a variable, use timer test results"

CodePudding user response:

Do you think this is for the sake of asynchronous induction,
That you don't have it, there is no need to turn behind others ass

CodePudding user response:

Asynchronous usage scenario is basically don't need to return the result, or return to the little influence on the results of the
Synchronization is must to return the result of

If you have 2 step operation series,
The first step is to query the user whether there is a
The second step, insert the user

So the first step you must await return, because there is you insert must lose
The second step is to see your own wishes, can be asynchronous or synchronous

CodePudding user response:

Simple say why asynchronous method to await? Because Microsoft to syntactic sugar ah, in fact you can don't write so

You can write a callback method, also can obtain the asynchronous results;

And Microsoft is in order to make asynchronous and synchronous converge on writing, so design the async and await this model;

Task in my impression is some first, then there is no async and await, want to get the asynchronous results can only write callback methods;

  •  Tags:  
  • C #
  • Related