mono Thread.Sleep(int) thrown System.TypeLoadException

本文关键字:thrown System TypeLoadException int Thread Sleep mono | 更新日期: 2023-09-27 18:12:39

我有以下问题:

Console.WriteLine("Starting");
Stopwatch stopWatch = new Stopwatch();
int delay = 1 * 60 * 1000;
int waitTime = delay - (int)(DateTime.Now.Second * 1000);
int time;
Console.WriteLine("PRE-Sleep");
Thread.Sleep(waitTime);
Console.WriteLine("AFTER-Sleep");

输出是:

Starting
PRE-Sleep
Unhandled Exception: System.TypeLoadException: A type load exception has occurred.
  at System.Threading.Thread.StartInternal () [0x00000] in <filename unknown>:0
[ERROR] FATAL UNHANDLED EXCEPTION: System.TypeLoadException: A type load exception has occurred.
  at System.Threading.Thread.StartInternal () [0x00000] in <filename unknown>:0

将Thread.Sleep(waitTime)更改为Thread.Sleep(1)会产生以下输出:

Starting
PRE-Sleep
AFTER-Sleep

一切正常

怎么可能呢?

mono --version
Mono JIT compiler version 2.10.8.1 (Debian 2.10.8.1-5ubuntu1)
Copyright (C) 2002-2011 Novell, Inc, Xamarin, Inc and Contributors. www.mono-project.com
 TLS:           __thread
 SIGSEGV:       altstack
 Notifications: epoll
 Architecture:  x86
 Disabled:      none
 Misc:          softdebug
 LLVM:          supported, not enabled.
 GC:            Included Boehm (with typed GC and Parallel Mark)

编辑:代码在Windows下使用Xamarin

mono Thread.Sleep(int) thrown System.TypeLoadException

运行良好

问题发现:它与线程无关。睡眠

应用程序读取一个cfg文件,在linux下没有链接。

Path.GetDirectoryName(Assembly.GetEntryAssembly().Location)

解决了问题