问题描述
我的应用程序概述
ASP.Net Web服务招待来自通过客户端数字签名和验证各种应用程序的请求。 WebService的然后将这些路由请求到智能卡
当系统日期的变化,我想下面的情况发生。
-
从客户新的要求都是为了等待
-
Web服务和智能卡之间目前的工作应该得到完成
-
如果有任何前挂起的请求,那么他们应该得到完成。
为什么我需要上面的事情发生的原因是,我需要关闭智能卡和web服务之间的现有会话。只有当文件没有签名/验证这应该发生。我不能只是关闭所有的对话,因为它可能会影响由线程中的任何一个被处理的文件。所以,我需要确保有互联网服务和智能卡之间没有当前活动的线程。
我写了一张code的这使得web服务和智能卡之间的活动线程的总数。
INT vWorkerThreads,vWorkerThreadsMax;
诠释vPortThreads,vPortThreadsMax;
系统:线程::线程池^ vThreadPool;
vThreadPool-> GetAvailableThreads(vWorkerThreads,vPortThreads);
vThreadPool-> GetMaxThreads(vWorkerThreadsMax,vPortThreadsMax);
ActiveThreadCount = vWorkerThreadsMax - vWorkerThreads;
这意味着,我还需要在客户端请求的等待?
清理机制:关闭PKCS#11使用API C_CloseAllSessions
和使用C_Finalize
通话将释放该库,以便它清除所有的会话对象。这应该是每天做一次。
我如何能完成这样的任务?任何想法
更新:
我可以在我的查询已经更加清晰。我想清楚地表明,我的目的不是要关闭ASP.NET web服务。 我的目的是要重置智能卡。由于我通过访问Web服务ASP.NET智能卡,我需要一个机制来进行重置智能卡的这个任务。
我给下面
当前进程PS: I am new to ASP.NET and Multithreading.
The question was updated in a big way, so bear with me...
Given that no threads are being created directly\indirectly by your web method code:
It is more helpful to rephrase the original question along the lines of "requests" rather than threads, e.g.
This is handled automatically as there is a concept of a request queue and active requests. When your ASP.NET application is restarted, all current and queued requests are completed (unless they do not complete in a timely fashion), and new requests are queued and then serviced when a new worker process comes back up. This process is followed when you recycle the Application Pool that your ASP.NET application belongs to.
You can configure your application pool to recycle at a set time in IIS Manager via the "Recycle" settings for the associated Application Pool. Presumably you want to do this at "00:00".
Update
I think I can glean from your comments that you need to run some cleanup code when all requests have been serviced and then the application is about to shut down. You should place this code in the global "Application_End" event handler.
Update 2
In answer to your updated question. Your requirements are:
When the application is restarted:
- New request from the clients are made to wait
- Current work between webservice and smart card should get completed
- If there is any prior pending requests then they should get completed.
This is supported by the standard recycling pattern that I have described. You do not need to deal with request threads yourself - this is one of the pillars of the ASP.NET framework, it deals with this for you. It is request orientated and abstracts how requests are handled i.e. serviced on multiple threads. It manages putting requests onto threads and manages the lifeclyle of those requests when the application is recycled.
Update 3
OK, I think we have the final piece of the scenario here. You are trying to shut down ASP.NET from your client by issuing a "CLOSED" web service call. Basicallyyou want to implement your own ASP.NET shut down behaviour by making sure that all current and queued request are dealt with before you then execute your clean-up code.
You are trying to re-invent the wheel.
ASP.NET already has this behaviour and it is supported by:
a. Application Recycling It will service outstanding requests cleanly and start-up a new process to serve new requests. It will even queue any new requests that are received whilst this process is going on.
b. Application_End A global application event handler where you can put your clean-up code. It will execute after recycling has cleanly dealt with your outstanding requests.
You do not need your "CLOSED" command.
You should consider letting IIS recycle your application as it has support for recycling at a specified daily time(s). If you cannot configure IIS due to deployment reasons then you can you use web.config "touching" to force a recycle out-of-bounds of IIS:
a. Have a timer running in the server which can check for the date change condtion and then touch the web.config file.
b. Still have the client call a "CLOSED" web method, but have the "CLOSED" method just touch the web.config file.
IIS, then "a" are the most desirable.
Honestly Microsoft have already thought about it. :)
Update 4
@Raj OK, let me try and rephrase this again.
Your conditions are:
- You have a requirement to reset your smartcard once a day.
- Before resetting your smartcard, all current and queued web service requests must be completed i.e. the outstanding requests.
- After outstanding requests are completed, you reset your smartcard.
- Any new requests that come in whilst this process is happening should be queued and then serviced after the smartcard has been reset.
These conditions allow you to complete existing requests, queue any new requests, reset your smartcard, and then start processing new requests after the card has been reset.
What I am suggesting is:
- Place your smartcard reset code in "Application_End".
- Configure IIS to recycle your application at "00:00". Ensure that in advanced settings for the associated Application Pool that you configure "Disable Overlapped Recycle = True".
- At "00:00" application recycling ensures that all current and queued requests will be completed.
- After "00:00" application recycling ensures that all new requests will be queued whilst requests in "3" are completed and the application performs shutdown steps.
- After requests in "3" are completed, "Applicaton_End" will be called automatically. This ensures that your smartcard is reset after all current requests are completed.
- Application recycling ensures that your application is re-started in a new process, and that new requests queued in step "4" start to be processed. The important thing here is that your reset code has been called in "5".
Unless there is some detail missing from your question, the above appears to meet your conditions. You wish to do "x,y,z" and ASP.NET has built-in support which can be used to achieve "x,y,z" and gives you mature, guaranteed and well-documented implementations.
I am still struggling to understand why you are talking about threads. I do multi-threaded development, but talking about threads instead of requests when thinking about ASP.NET adds unnecessary complexity to this discussion. Unless your question is still unclear.
Perhaps you are missing the point I'm making here. I am drawing a parallel between the behaviour you require when you call "CLOSED" from your client application, and what happens when you recycle an application. You can use recycling and "Application_End" to achieve the required results.
I am trying to help you out here, as trying to implement this behaviour yourself is unnecessary and non-trivial.
这篇关于关闭,如果没有活动线程,或者如果有任何活动,然后等待,直到它的完成并关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!