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) {
///& 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,