Home > Net >  Ref asynchronous thread parameters are used to
Ref asynchronous thread parameters are used to

Time:09-28

Before the new limited understanding to some concepts, wrote a test were used in the production, to optimize the original program, step by step to make logical architecture more clearly, now rewrite a method using the ref parameters, found that if there is asynchronous thread will prompt wrong, can you tell me how to avoid?
Thread synchronization speed too slow, temporary not consider

Thank you,

Private void test (ref int test)

{
.
Task. Run (()=& gt;
{
If (test & lt; 1)
{
Sect_disp (0);
.

CodePudding user response:

In asynchronous, anonymous methods (functions), lambda expressions such as scene is not allowed to use the ref or out parameters out, you need to modify the code to avoid this to happen, or do not use the ref or out, or do not use asynchronous,

CodePudding user response:

Doesn't support, and I don't want to out,

CodePudding user response:

So why do you ref?

People also need to know the ref outside?
If want to know his outside, can task , can entrust to return, can IProcess notice

CodePudding user response:

I probably understand what you mean,

You don't use Task. Run
For the Task. Factory. StartNew (Action, object)
the overloading methodHand in the parameters,

If you need to return values
To the Task. Factory. StartNew ((x)=& gt; {return (int) x + 1; }, object)

CodePudding user response:

The
reference 3 floor wanghui0380 response:
so could you please tell me why you want to ref?

People also need to know the ref outside?
If want to know his outside, can task , can entrust to return, can IProcess Notice


Before because of the function of the need to retest, according to my bosses, don't use the ref parameter before, is as follows:

1, public partial class Form1: Form, defines a global variable for the int passednr, the variable records the DUT has passed the test project,
2. Encapsulates a test method for private void test (int test), there are 21 test project, if the incoming test=0, represents the first started testing, test> 0 (for example test=5, said before have test by five, starting from the item 6 test) represents retest, test project is based on a series of Telnet related instruction response validation, use asynchronous way,
3. Packaging of the following methods, in the case of items through/I or NG calls, logic is that if a test pass, passednr + 1 operation is needed to (not through the exit),
According to this logic, if add the ref in, feel variable will be less, logic will be more clear,


Public void Test_Ok (int I)
{
Passednr++;

This. Invoke (new EventHandler (delegate
{

ListView1. Items [I] ForeColor=Color. Green;

}));

}
Public void Test_Ng (int I)
{
Locallog. WriteLog (" "+" checklists, [I] + "" +" test to fail, "LogName);
This. Invoke (new EventHandler (delegate
{

ListView1. Items [I] ForeColor=Color. Red;
Label4. Text="NG";
Label4. ForeColor=Color. Red;
TextBox2. Enabled=true;
TextBox2. Focus ();


}));

CodePudding user response:

Can consider to use entrusted to realize through the callback function to obtain the return value

CodePudding user response:

Oh, you need to know the final processing position

This USES the

Task Processing method ()
{

}

CodePudding user response:

Ps: this order of things, usually by cor or pipeline mode

You need to save the context, which is equivalent to any a link link failure, return to the time of the context, serialization to save, was restored to arrange another time call context

Now it is day way asp.net core, also used in the pipeline mode, the so-called Middleware, fantastic short-circuit Middleware, fusing Middleware, is this really was actually originally do not have what thing "myth"

CodePudding user response:

https://www.cnblogs.com/stulzq/p/7760648.html

Myth asp.net core
  •  Tags:  
  • C#
  • Related