Im doing a web application that will play a media. I have a class A that contains a method ,say MyMethod:
public void MyMethod()
{
.....
Process proc = ....
ThreadPool.UnsafeQueueUserWorkItem((o) =>
{
proc.WaitForExit();
proc.Close();
.....
},null);
}
in code behind of my page I will call this method that will run the process and then will play the media, the process converts file to .flv type.My problem is becoz im using an asynchronous system,even if the thread didnt finish its work on unload, the pag开发者_高级运维e will load but without playing the media. How can i wait for the process inside the ThreadPool to terminate ? and THEN load my page ?? thanks alot.
if you want your asp.net resqponse to wait for the process result, call WaitForExit directly. Don't use the ThreadPool.
If for some reason you feel you absolutely need to use the ThreadPool, you can use a ManualResetEvent to wait for the result in the calling thread.
精彩评论