Home > Net >  Thread and asynchronous problem for help
Thread and asynchronous problem for help

Time:10-22

Colleagues to write code that WCF service end all service method in a Task, I think it is unnecessary, can't persuade him, since here to consult, if the code has a problem, all the projects in the company, influence also pretty big,
WCF service client code:
 public List GetDeviceListAll () 
{
If (HI. Get (a). CheckTicket ())
{
Var result=FactoryStartNew. StartNewThread (()=& gt; {return HI. Get GetDeviceListAll () (); });
return result;
}
Return new List (a);
}

FactoryStartNew. Cs code:
 using System; 
using System.Collections.Generic;
using System.Linq;
using System.Text;

The namespace SunCreate.Common.Com Lib
{
///& lt; Summary>
///2018-12-19 BY: Leon (do not modify the code)
///& lt;/summary>
Public class FactoryStartNew
{
Private static log4net. ILog m_Log=log4net. That the LogManager. GetLogger (typeof (FactoryStartNew));

///& lt; Summary>
///by thread running function
///& lt;/summary>
///& lt; Param name="action" & gt; Run the function & lt;/param>
Public static void StartNewThread (Action Action)
{

System. Threading. Tasks. Task va=System. Threading. Tasks. Task. Factory. StartNew (()=& gt;
{
Try
{
The action ();
}
The catch (System. Exception ex)
{
M_Log. Error (ex);
}
})
ContinueWith (o=& gt; {return; });
Va. Wait ();
}

///& lt; Summary>
///by thread running function
///& lt;/summary>
///& lt; Typeparam name="TResult & gt;" The return value type & lt;/typeparam>
///& lt; Param name="action" & gt; Run the function & lt;/param>
///& lt; Returns> The return value & lt;/returns>
Public static TResult StartNewThread (Func The action)
{
Try
{
TResult bRst;
System. The Threading. Tasks. Task Va=System. The Threading. Tasks. Task. Factory. StartNew (()=& gt;
{
Return the action ();
})
. ContinueWith (o=& gt; {return o.R esult. });
BRst=va. Result;
Return bRst;
}
The catch (System. Exception ex)
{
M_Log. Error (ex);
Return the default (TResult);
}
}
}
}

CodePudding user response:

Your colleague in imitation, is in an attempt to mimic the interface async/await

CodePudding user response:

You use jmeter to a 1000 threads concurrent test for him,
And then he knew

CodePudding user response:

This pair of, a rising tide lifts all boats,

Level of less than, we also don't want to say what, say more afraid drown you, after all ship has sink, and water will be flooded with


Ps: task belongs to parallel programming (and blog garden powder of different places, I don't what things are called concurrent, concurrent), he raised the parallel ability, nor parallel visualization parallel, of course, limited resources limit when the system is the blog of garden pink mouth concurrent

Problem is that your system need improve the ability of parallel, 100 client access to a natural don't need to 1 hour, 1 minute 10000 client access to a need to optimize the parallel, 1 seconds 10000 client access requires concurrency control,
So, we don't discuss you who to who wrong, only need not need system are also discussed

CodePudding user response:

Typical to do simple things complicated, a Task starts, Wait directly, gild the lily,

CodePudding user response:

reference wanghui0380 reply: 3/f
this pair of, a rising tide lifts all boats,

Level of less than, we also don't want to say what, say more afraid drown you, after all ship has sink, and water will be flooded with


Ps: task belongs to parallel programming (and blog garden powder of different places, I don't what things are called concurrent, concurrent), he raised the parallel ability, nor parallel visualization parallel, of course, limited resources limit when the system is the blog of garden pink mouth concurrent

Problem is that your system need improve the ability of parallel, 100 client access to a natural don't need to 1 hour, 1 minute 10000 client access to a need to optimize the parallel, 1 seconds 10000 client access requires concurrency control,
So, we don't discuss you who to who wrong, only discuss system need not


Hundreds of client, colleagues solve with the Nginx, more than a few service side, resistance to live,
Another problem is that the original WCF service side there is no try catch, then the server crash, with this, plus inside a try catch, always don't collapse,
Old didn't know that the chemical composition in the medicine of traditional Chinese medicine, he is can cure disease, it may not cure you,

CodePudding user response:

There is something wrong with the words, the code looks oh, parallel is parallel to the

Return value problem, tsak a startup, immediately returned, the result is null

CodePudding user response:

Oh, wrong and right, he result synchronization results to get the

So, it's just like in the upstairs said, well enough alone, in fact, he eventually synchronous blocking and didn't write

Again, a rising tide lifts all boats, level of less than, forced to infuse water, the boat sank

We play in other posts also said, the first clear parallel, concurrent, and asynchronous, synchronous and in the lane, this is not sure, don't dig a hole

CodePudding user response:

autumn rain lotus cheung reference 5 floor response:
Quote: refer to the third floor wanghui0380 response:
this pair of, a rising tide lifts all boats,

Level of less than, we also don't want to say what, say more afraid drown you, after all ship has sink, and water will be flooded with


Ps: task belongs to parallel programming (and blog garden powder of different places, I don't what things are called concurrent, concurrent), he raised the parallel ability, nor parallel visualization parallel, of course, limited resources limit when the system is the blog of garden pink mouth concurrent

Problem is that your system need improve the ability of parallel, 100 client access to a natural don't need to 1 hour, 1 minute 10000 client access to a need to optimize the parallel, 1 seconds 10000 client access requires concurrency control,
So, we don't discuss you who to who wrong, only discuss system need not


Hundreds of client, colleagues solve with the Nginx, more than a few service side, resistance to live,
Another problem is that the original WCF service side there is no try catch, then the server crash, with this, plus inside a try catch, always don't collapse,
Old didn't know that the chemical composition in the medicine of traditional Chinese medicine, he is can cure disease, it may not cure you,

Collapse that is didn't do before the exception handling, this made (a simple catch exceptions can prevent collapse has nothing to do with the Task), use the Task is not an option,

CodePudding user response:

Also don't say Chinese medicine of traditional Chinese medicine, not least from the prescription can see things

If ( HI. Get (). CheckTicket
()){
var result=FactoryStartNew. StartNewThread (()=& gt; {return HI. Get GetDeviceListAll () (); });
return result;


}

nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  •  Tags:  
  • C#
  • Related