Home > Net >  Bosses, is there a better way of thinking to every five open a thread to update data?
Bosses, is there a better way of thinking to every five open a thread to update data?

Time:11-26

ORM use EF6, such as: is there a better way of advice or to every five open a thread to update data?

Logic, for example: article database with 1000 data need to be updated, but this article 1000 data interface need to request a third party or to update the data to the results, and needs to be updated regularly, every 3 s are going to finish the 1000 data

CodePudding user response:

The questions don't understand, you want what?

I also don't want to guess, as each of your five update

Don't want to write so many complex code, the use of recent human thinking mode of Reactive Extensions (Rx) for. NET
Nuget introduced
System. Reactive

Subject Xx=new Subject (a); T I don't know is what, I fill out
according to the circumstance
//here you have the thread, the parallel or I don't care
If you receive a data

Xx. OnNext (receive)

Xx. Buffer (5)//cache 5
Subscription (lst5=& gt; {
//the lst5 are 5 a set, you want yourself to update the database
})

CodePudding user response:

reference 1st floor wanghui0380 response:
questions don't understand, what you want on earth?

I also don't want to guess, as each of your five update

Don't want to write so many complex code, the use of recent human thinking mode of Reactive Extensions (Rx) for. NET
Nuget introduced
System. Reactive

Subject Xx=new Subject (a); T I don't know is what, I fill out
according to the circumstance
//here you have the thread, the parallel or I don't care
If you receive a data

Xx. OnNext (receive)

Xx. Buffer (5)//cache 5
Subscription (lst5=& gt; {
//the lst5 are 5 a set, you want yourself to update the database
})


Thank you, look not to understand

CodePudding user response:

Don't need you read and understand the meaning can

The
reference
Subject Subject=new Subject (a);
Private void Form2_Load (object sender, EventArgs e)
{

Observables. Interval (TimeSpan. FromSeconds (3))//every 3 seconds to produce an action
The Subscribe (async p=& gt;
{
for (int i=0; i <1000; I++)
{
Subject. OnNext (await get int (I));
}


});


//
Subject. Buffer (5). The Subscribe (LST=& gt;
{
Trace. WriteLine (string. Join (", ", LST));
});




}

The Random rad=new Random (DateTime. Now. Millisecond);
Async Task Get int (int I)
{
//simulate a time-consuming requests, a random 300-800 milliseconds returned
Await Task. Delay (TimeSpan. FromMilliseconds (rad) Next (300, 800)));
Return the I;
}


Run a simulation, we can complete your request,

But this kind of thing you see just, don't use, because your request is actually difficult, IO and CPU load is very high (although I run this simulation code have no pressure, but really run business code, estimates some disadvantaged, do not recommend rely on single machine code completion,

Access request does not necessarily guarantee back in sequence at the same time, so if is the question of the insert is not big, if you update is the same, it will make a great question,
If the update is the same, it is recommended that the partial time request, is a time request 5 (don't repeat the same batch request), because the requirements are abandoned data (I need data 3 seconds ago, and I want to be the current data)

CodePudding user response:

You said five data one thread, you do not like that?
Say you drive so multithreading does not necessarily fast ah, after all, limited resources, and update the data you are, this goes to lock, originally a minutes of things get ten minutes

CodePudding user response:

Multi-user command to update the data is to have a "database transaction" blocking, so whether it's a process, or the multiple processes to concurrent updates data, are blocked, but read data is concurrent processing, can use the
 await Task. WhenAll (tasks); 
statement to asynchronous wait end of multiple tasks,

CodePudding user response:

The great god sp1234 resurrection.
  •  Tags:  
  • C#