workerThreads = new Thread[5];
finishEvents = new AutoResetEvent[5];
//
// set threads and start them.
//
for (int i = 0; i < workerThreads.Length; i++)
{
Thread thread = new Thread( new ThreadStart( this.Worker ) );
thread.Name = "Worker" + (i + 1).ToString();
thread.IsBackground = true;
workerThreads[i] = thread;// storing worker threads into array.
    finishEvents[i] = new AutoResetEvent(false);// storing AutoResetEvent for finish notice.
thread.Start();
}
//
// change state.
//
this.ChangeState(TaskState.Running);
//
// wait for finish all.
//
try
{
    WaitHandle.WaitAll(finishEvents);
}
catch
{
    //
    // exception happend here.
    //
}
//
// continue code...
//这段代码在单机版里一点问题没有,换到Remoting下就经常出现下面的错误,但也不是每次都出现.这是什么意思?无法将类型为“System.Runtime.Remoting.Messaging.TransitionCall”的对象强制转换为类型“System.Runtime.Remoting.Messaging.IMethodCallMessage”

解决方案 »

  1.   

    查过了,不是Worker抛出来的.try
    {
        WaitHandle.WaitAll(finishEvents);
    }
    catch
    {
        //从这里能捕获取,Worker里面试了捕获不到!!! 所以不是Worker抛出来的.
    }是AutoResetEvent在remoting下的问题吧?? 哪位可以分析一下?
      

  2.   

    to aafshzj:try
    {
        WaitHandle.WaitAll(finishEvents);
    }
    catch
    {
        //如果其它地方抛异常,这里是捕获不到的啊.而且Worker里面试了捕获不到!!! 
    }
      

  3.   

    无法将类型为“System.Runtime.Remoting.Messaging.TransitionCall”的对象强制转换为类型“System.Runtime.Remoting.Messaging.IMethodCallMessage”一个是类对象的实例,一个是接口.
    肯定还是什么实例化的不对建议楼主把Try Catch加的再外面一点多试试
      

  4.   

    这个是.NET内部类,确实不好搞明白,估计只有微软内部的工程师会知道. 算了,不问了,忽略异常算了,反正不影响执行. 结贴!!!