Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/279.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/multithreading/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 多线程处理时企业库日志记录出错_C#_Multithreading_Enterprise Library - Fatal编程技术网

C# 多线程处理时企业库日志记录出错

C# 多线程处理时企业库日志记录出错,c#,multithreading,enterprise-library,C#,Multithreading,Enterprise Library,我在尝试在新线程中使用Microsoft企业库日志记录时遇到问题。下面是我用来启动线程的代码: Thread cleanupThread = new Thread(new ThreadStart(DirectoryCleanup)); cleanupThread.Start(); 在DirectoryCleanup方法中,在以下行上引发错误: Logger.Write(ex.Message, "General", 100, 0, System.Diagnostics.TraceEventTy

我在尝试在新线程中使用Microsoft企业库日志记录时遇到问题。下面是我用来启动线程的代码:

Thread cleanupThread = new Thread(new ThreadStart(DirectoryCleanup));
cleanupThread.Start();
在DirectoryCleanup方法中,在以下行上引发错误:

Logger.Write(ex.Message, "General", 100, 0, 
System.Diagnostics.TraceEventType.Critical);
下面是我得到的错误:

The type initializer for 'Microsoft.Practices.EnterpriseLibrary.Logging.Logger' 
threw an exception.
以下是内部异常:

{"Could not load file or assembly 'Microsoft.Practices.EnterpriseLibrary.Common,
Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its
dependencies. The system cannot find the file specified.":"
Microsoft.Practices.EnterpriseLibrary.Common, Version=4.1.0.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35"}  
记录器在程序的主线程中工作正常。它只有新线程的问题。我花了很多时间寻找,但似乎找不到答案。 谢谢你的帮助

更新:

我尝试使用以下代码使用线程池:

Task.Factory.StartNew(DirectoryCleanup);

它产生了与上面相同的错误。

创建自己的线程有什么原因吗?在使用线程池中的线程时,您是否遇到同样的问题?QueueUserWorkItem(…)我是线程新手。只是学习如何使用它。我还没有经常使用线程池。我会试试看是否有什么不同。即使我目前的方法行不通,我还是想理解为什么它行不通。由于线程正在同一appdomain中运行,因此该错误应该是不可能的?因此,如果日志记录在主线程中工作,那么它也应该在另一个线程中工作。dll(
Microsoft.Practices.EnterpriseLibrary.Common
)要么加载到appdomain中,要么不加载。你要么错了,要么做了一些非常奇怪的事情;)我对线程也很陌生,但值得一试。我同意它应该工作,因为所有东西都在同一个appdomain中。这是一个奇怪的错误,这就是我问这个问题的原因。我是否可以提供任何其他信息来帮助阐明问题是什么?