代码:
public Db4oQueueService(Uri baseUri, bool resume)
{
string fileName = Path.GetFullPath("MyQueue_{0}.Yap".FormatWith(baseUri.GetHashCode()));
m_Db = Db4oEmbedded.OpenFile(Db4oEmbedded.NewConfiguration(), fileName);
if (!resume)
{
ClearQueue();
}
}
例外
Db4objects.Db4o.Ext.DatabaseFileLockedException was unhandled by user code
Message=SeleniumWinDemo\bin\Debug\MyQueue_177598820.Yap
Source=Db4objects.Db4o
StackTrace:
at Db4objects.Db4o.IO.RandomAccessFileFactory.NewRandomAccessFile(String path, Boolean readOnly, Boolean lockFile)
at Db4objects.Db4o.IO.FileStorage.FileBin..ctor(BinConfiguration config)
at Db4objects.Db4o.IO.FileStorage.Open(BinConfiguration config)
at Db4objects.Db4o.IO.StorageDecorator.Open(BinConfiguration config)
at Db4objects.Db4o.IO.CachingStorage.Open(BinConfiguration config)
at Db4objects.Db4o.Internal.IoAdaptedObjectContainer.OpenImpl()
at Db4objects.Db4o.Internal.ObjectContainerBase._IRunnable_125.Run()
at Db4objects.Db4o.Foundation.DynamicVariable.With(Object value, IRunnable block)
at Db4objects.Db4o.Foundation.Environments.RunWith(IEnvironment environment, IRunnable runnable)
at Db4objects.Db4o.Internal.ObjectContainerBase.WithEnvironment(IRunnable runnable)
at Db4objects.Db4o.Internal.ObjectContainerBase.Open()
at Db4objects.Db4o.Internal.IoAdaptedObjectContainer..ctor(IConfiguration config, String fileName)
at Db4objects.Db4o.Internal.ObjectContainerFactory.OpenObjectContainer(IEmbeddedConfiguration config, String databaseFileName)
at Db4objects.Db4o.Db4oEmbedded.OpenFile(IEmbeddedConfiguration config, String databaseFileName)
at Db4oServices.Db4oQueueService..ctor(Uri baseUri, Boolean resume) in D:\PROJEKTI\Db4oServices\Db4oQueueService.cs:line 27
at Db4oServices.Db4oServicesModule.<Load>b__1(IComponentContext c, IEnumerable`1 p) in D:\Db4oServices\Db4oServicesModule.cs:line 36
at Autofac.Builder.RegistrationBuilder.<>c__DisplayClass1`1.<ForDelegate>b__0(IComponentContext c, IEnumerable`1 p)
at Autofac.Core.Activators.Delegate.DelegateActivator.ActivateInstance(IComponentContext context, IEnumerable`1 parameters)
at Autofac.Core.Resolving.InstanceLookup.Activate(IEnumerable`1 parameters)
at Autofac.Core.Resolving.InstanceLookup.Execute()
at Autofac.Core.Resolving.ResolveOperation.GetOrCreateInstance(ISharingLifetimeScope currentOperationScope, IComponentRegistration registration, IEnumerable`1 parameters)
at Autofac.Core.Resolving.ResolveOperation.ResolveComponent(IComponentRegistration registration, IEnumerable`1 parameters)
at Autofac.Core.Resolving.ResolveOperation.Execute(IComponentRegistration registration, IEnumerable`1 parameters)
InnerException: System.IO.IOException
Message=The process cannot access the file 'SeleniumWinDemo\bin\Debug\MyQueue_177598820.Yap' because it is being used by another process.
Source=mscorlib
StackTrace:
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)
at Sharpen.IO.RandomAccessFile..ctor(String file, Boolean readOnly, Boolean lockFile)
at Db4objects.Db4o.IO.RandomAccessFileFactory.NewRandomAccessFile(String path, Boolean readOnly, Boolean lockFile)
InnerException:
如何防止此异常。我可以先发布 .yap 文件吗?