开发者

C#: Any way to pause the thread process that the resource used by that thread are released

Can this solution work? Is there a way to indefinitely pause a thread

Is the reso开发者_运维问答urces released with this solution?


In short, no. The only way to stop what a thread is doing and release any resources being used is to Abort it (Thread.Abort method).


Unless there is a lot more to this question, just end the thread at an "indefinite" pause and create a new thread after the pause. When the thread isn't running just release all the restorable data/resources that make sense (from within the thread itself, if possible). Take time to come up with a clear life-cycle and resource-ownership model. In general, let the thread be "cooperative" and manage its own resource lifetime.

The general create/start/thaw/work/freeze/stop phases is the underlying basis of many long-running and/or pause-able jobs such as SharePoint Timers, Windows Workflow Tasks or SQL Server agents. Note that there is no "suspended indefinitely" phase in the list above -- this is just the space between the create and the start (or the stop and the next start) and is normally where external events enter the system.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜