我正在一个紧凑框架项目上使用线程,并且代码如下所示。当我尝试进入 StartThreads() 时,会抛出 NotSupportedException。这看起来有点奇怪,为什么异常是在调用 StartThreads() 的行上抛出的,而不是在内部抛出的,CF 不支持什么?我认为它是 ThreadStart.BeginInvoke 但这并不是实际抛出异常的地方。
void SomeMethod()
{
this.StartThreads(); // <- NotSupportedException is thrown here, I can't step into this method with the debugger
}
void StartThreads()
{
ThreadStart threadStart = BeginDoStuff;
threadStart.BeginInvoke(EndDoStuff, null);
}
CF 不支持 BeginInvoke 机制以及 ThreadPool。
您没有在预期的位置看到异常的原因是其实现方式所致。我不完全确定细节,但 BeginInvoke 不是(委托类的)普通方法,而是在运行时注入的方法(只是猜测最后一部分)。
当 JIT 编译器开始处理 StartThreads 方法时,会发生该错误。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)