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”
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”
{
WaitHandle.WaitAll(finishEvents);
}
catch
{
//从这里能捕获取,Worker里面试了捕获不到!!! 所以不是Worker抛出来的.
}是AutoResetEvent在remoting下的问题吧?? 哪位可以分析一下?
{
WaitHandle.WaitAll(finishEvents);
}
catch
{
//如果其它地方抛异常,这里是捕获不到的啊.而且Worker里面试了捕获不到!!!
}
肯定还是什么实例化的不对建议楼主把Try Catch加的再外面一点多试试