Waithandle override
Jeg har følgende forsimplet kodepublic delegate void CrossDomainSearchDelegate(TSE_RQ RQ, MemoryStream ms);
public class WaitHandle_NeverDies : WaitHandle
{
public override object InitializeLifetimeService()
{
return (null);
}
}
public static partial class ModulesCommando
{
public static TSE_AvailRS[] Search(ModulesCommandoRequest[] modulesCmdReqList)
{
<....... cut ......>
WaitHandle_NeverDies[] waitHandle = new WaitHandle_NeverDies[modulesCmdReqListLength];
System.IO.MemoryStream[] memoryStreamList = new System.IO.MemoryStream[modulesCmdReqListLength];
<....... cut ......>
CrossDomainSearchDelegate searchDelegate = new CrossDomainSearchDelegate(ModuleLoader.CrossDomainSearch);
System.IO.MemoryStream resultMemoryStream = new System.IO.MemoryStream();
IAsyncResult iAsyncResult = searchDelegate.BeginInvoke(RQ, resultMemoryStream, null, null);
WaitHandle_NeverDies wh = (WaitHandle_NeverDies)iAsyncResult.AsyncWaitHandle;
memoryStreamList[i] = resultMemoryStream;
waitHandle[i] = wh;
WaitHandle_NeverDies.WaitAll(waitHandle);
<....... cut ......>
}
}
Det jeg forsøger på, er at override funktionen InitializeLifetimeService() i klassen WaitHandle via klassen WaitHandle_NeverDies, det virker sådan set også, men i ovenstående kode går det galt i flg. linie
WaitHandle_NeverDies wh = (WaitHandle_NeverDies)
iAsyncResult.AsyncWaitHandle;
fordi man ikke kan lave en cast fra WaitHandle til WaitHandle_NeverDies, og det forstår jeg godt at man ikke kan, men mit spørgsmål er, hvordan skal jeg så override funktionen InitializeLifetimeService() så jeg opnår det jeg vil?