I am writing a library which writes something into the database for temporary use (use only once) and then gets removed (its strange, but there is a certain implementation necessary for this ). For this I am trying to execute a thread which writes in the data into the database, waits for the page to finish loading and then releases to finish executing, removing the record. I am not sure how to apprach this. One way is to make the thread sleep but then I am risking either not allowing enough time or the thread might still be running after the page has finished doing everything else. Is there a way to tie this into the page thread so I can release my thread right after it finishes? What are some, if any, approaches to something like this? Because this is a library I would much rather not have another programmer call a function at the end of his page code to remove the record; its messy and easily forgotten.
質問する
240 次
2 に答える
1
他の理由 (教育など) でスレッドを使用する場合を除き、アプリケーション イベントの使用を検討してください。必要に応じてAcquireRequestStateとReleaseRequestStateまたは同様のペアをリッスンし、データベース操作を実行できます。アプリケーションのライフサイクルをチェックして、すべてのイベントとその順序を確認してください。
于 2012-07-02T16:01:07.170 に答える
-1
なぜ別のスレッドを作成するのですか?Load イベントでレコードを書き込み、Unload イベントで削除します。
于 2012-07-02T15:57:29.980 に答える