Home > Net >  Asp.net how to wait for a child thread end
Asp.net how to wait for a child thread end

Time:11-06

I want to Application_End () wait for the end of a child thread safety,

In IIS, when the administrator stop website, I hope that the child thread save the data, and then the safety exit, didn't stop after the web site,

But, I have the following code, in sbThread. The Join (), the NET will be after waiting a moment, force quit, simply wait for my background background threads to save data,

As a result, the child thread only save half of the data, the rest is lost,

 protected void Application_End (object sender, EventArgs e) 
{
Thread workThread;
The lock (dataStore. SbpSync)
{
WorkThread=dataStore. WorkThread;
DataStore. Exiting=true;
DataStore. AutoEvent. The Set ();
}
If (workThread!=null)
WorkThread. The Join ();
}


As we write desktop applications, program exits before, need to save the data, Asp.net should have this mechanism?

CodePudding user response:

By the way, I am a child thread scenario:

I'm integrate Paypal payment systems, Paypal will send the payment schedule to my web site, failure, reason, refund, controversial events,

I received after these events, have the same back to them, in order to verify the authenticity of these events, to ensure that they are not third party forged,

So I enable a background thread, will receive the event queue, back to Paypal, such as send failed due to network reasons, will resend (up to 12 times, and the period 2 days), until it is sent successfully,

When master stop website, I hope that these "event data can be saved," next time site restart, then hair,

CodePudding user response:

Asp.net is, there is no mechanism to ensure the safety of the child thread data said exit is forced out of the race?

I just received "events", the website is pulled out, wouldn't it be pulled eggs?

CodePudding user response:

Eldest brother now that your data is so important, you should be all the operation should be in the form of you bypass the log, the operating system cache as a program dedicated to receive the data, and then send another program and write the log, the third program is send receive time log archive, nothing is made any system, IIS can also don't want to bother writing database,

CodePudding user response:

Well, what do you mean, you are not immediately send, there is a queue is hair

This queue is memory, restart the application pool he lost, so I need before restart persistence

If I understand right, then we say, you need a can persist the queue, rather than by myself before the restart (the worst situation is blue screen, power down, that stop you, so you need to he can lasting)

So, willing to accept new things, not things you can use the rabbitmq, Microsoft activmq, reluctant to the Microsoft program will open on the server side MSMQ Microsoft message queue

These are automatically persisted

CodePudding user response:

Upstairs, you this is wrong, of course, thank you for your reply,

Whatever the Web server, when it stops, must be close port 80 listen first, and then wait for the child thread safe exit,

If this is not the case, the server shall require, any child thread then you will lose data, whether you are writing log, or a database, I just received a data, you cross Cha dropped out, I do all useless,

Also can be concluded that the Web server does not support the child thread, if you want to use the child thread, is bound to accept the "missing data",

Thinking now is that I use Task instead of the Thread, let "back to check" business in the Thread pool implementation of the system, to see if the IIS can make it safe exit

CodePudding user response:

What we don't want to discuss the application pool should be waiting for you to end, he didn't end, because you want to a lifetime is not over, he that's trouble
Such as the window to turn it off will tell you that may pop up a box xx program to death does not end, he stop off

We just tell you, please open the MSMQ and seeing the results, you will find that the world is not the same (although MSMQ is not a new thing, almost as old as MSSQL, but you can't see him, perhaps a lifetime all can't see)



  • Related