I call service method using
ThreadPool.QueueUserWorkItem(o => service.Method(arg1, arg2));
Service has object ‘loggingService’ with I was get using Spring.Net
private readonly ILoggingService loggingService = ObjectBuilder.GetObjectByName("LoggingService");
‘LoggingService’ class is singleton. It writes log info to log.txt.
When I try to call loggingService.Info(“test”) in this service method, I get exception: file is busy by another process.
How can I access to the loggingService?
Your singleton is apparently per-thread.
You will need some way of passing the
LoggingServiceacross threads.For example, you could set
service.loggingServicein the original thread.Alternatively, you might be able to configure Spring.Net to make it a non-thread-local singleton.
Note that your LoggingService must be thread-safe, or you’ll get strange errors at runtime.