|
Hi,
In my windows application i am using file dialog box for uploading the file. If the file is in use i am not able to upload its giving exception.
How can i solve it,i mean to say if still the file is in use i want to upload it.
Can any one suggest me how can i do it ?
Thanks in advance.
|
|
|
|
|
If another application has the file open, and locked for reading, you cannot read from it. That's an OS level restriction. You can give yourself a chance by requesting a read-sharable lock to the file yourself:
FileStream fs = File.Open(filename, FileMode.Open, FileAccess.Read, FileShare.Read);
This will succeed where an attempt to open the file read/write won't if another application has done the same thing. However, most applications lock files completely while in use (and some, notably MS Office, keep the file locked while it is open ... bad practice, that), and there is simply no way to read such a file while the other application has it open.
Check that your own application isn't opening a file and forgetting to close it, though. That's a good way of creating this exception that can be fixed. You can generally put a FileStream or StreamReader in a using block which makes sure it is always closed.
|
|
|
|
|
thanks it helped me a lot.
|
|
|
|
|
BobJanova wrote: This will succeed where an attempt to open the file read/write won't if another application has done the same thing. However, most applications lock files completely while in use (and some, notably MS Office, keep the file locked while it is open ... bad practice, that), and there is simply no way to read such a file while the other application has it open.
I don't agree on you that it is bad practice. If MS Word is doing intermittent writes to it and share it for reading, then another application reading the file could get strange results, where the first half of the file is 'old' and the second half is 'new'. Locking files (appropriately) while in use is a good thing.
Consider a user deleting a file, and it keeps coming back. "Why is this happening?!". Because the application that is writing to the file doesn't have it locked, so at every write it comes back*. With locks, the user gets the immediate error that the file is in use.
The lock is there because the file is in use, and access to it can't reasonably work properly, so it is protecting other applications.
* slightly fictional situation, but it is a good example of why files have locks
|
|
|
|
|
The file should be locked against reading when it is actually being written. In a document editing app, that should be the time between pressing 'Save' and the save completing. There's no reason for a program like Word (or Adobe Reader, lest ye think I'm just being anti-Microsoft) to hold the file open the entire time you are looking at it.
The basic point I'm trying to make is that yes, locks are for when the file is in use. Once a document is loaded, it is in memory and the file shouldn't be in use; you should be able to open, delete, edit it etc in another editor (as you can with text editors, image editors etc) while it is being viewed in one editor.
This is kind of a tangent but I don't mind because I think the OP already got a good answer.
|
|
|
|
|
BobJanova wrote: There's no reason for a program like Word (or Adobe Reader, lest ye think I'm just being anti-Microsoft) to hold the file open the entire time you are looking at it
Writing to a text-file is not an atomic operation. Having people read incomplete information might result in bugs that are hard to track.
Bastard Programmer from Hell
|
|
|
|
|
I don't think I can have explained this well. It is absolutely correct that, while the file is being saved, it is locked. What these programs do is lock the file the whole time you are looking at it (i.e. not just when it's updating the file).
|
|
|
|
|
Yes. Word locks the file, and keeps a temporary copy - the file is being edited, and cannot be saved in between. It might take 30 minutes to update the file.
Time for me to get some sleep, I guess I'm missing the point here
Bastard Programmer from Hell
|
|
|
|
|
BobJanova wrote: The file should be locked against reading when it is actually being written. In a document editing app, that should be the time between pressing 'Save' and the save completing.
You make a very valid point there. However, the implementation holds some problems and I guess that's why it is the way it is now. I'm thinking that if Word would do that, and another program decides to start reading from the file (thus locking it temporarily for writes), any save or write from Word would have to wait until the other program releases its lock. Now, if it is a well behaved program, this might only take a few seconds, but then still, it adds a few seconds to any file write, which can be annoying. This problem you could work around by the OS caching the writes (or the reads) of the other program.
Now, suppose the other program is not so well behaved and keeps the read lock for minutes. Then we have Word hanging, or if it's cached the responsibility of the OS to keep all changes to the file cached for a very long time.
Well, I guess that it could work if the OS supported it. But only then. As it is now, any program that would try to be 'friendly' and release the lock between writes would become very vulnerable to IO-blocking by other programs. It could be done maliciously, for instance, to indefinitely halt execution of an application.
It is indeed a tangent, but I find it interesting to think about the possibilities
|
|
|
|
|
Hi.
Can anyone tell me why when i compile same code in Framework 4.0 target and 2.0, in 4.0 small count of videos can be played, in 2.0 all available formats are being played and captured correctly.
What's the point of that ?
|
|
|
|
|
None, and the problem is too vague to answer. Do you have any code that can be used to replicate the problem?
Bastard Programmer from Hell
|
|
|
|
|
|
There's a forum at the bottom of that[^] page; if you post a question there, the author of the article will get an email.
To answer the question; I guess there's a difference in the versions of DirectX installed.
Bastard Programmer from Hell
|
|
|
|
|
Hi all ! I have that code below:
How can i connect the graph and IBasicVideo to NullRenderer ? I have it already working but with IVideoWindow, how to use NullRenderer instead of IVideoWindow and get the same results ?
Thanks in advance!
BTW: Sorry for my english
private void BuildGraph(){
int hr = 0;
this.graphBuilder = (IGraphBuilder)new FilterGraph();
hr = this.graphBuilder.RenderFile(filename, null);
DsError.ThrowExceptionForHR(hr);
this.mediaControl = (IMediaControl)this.graphBuilder;
this.mediaEventEx = (IMediaEventEx)this.graphBuilder;
this.mediaSeeking = (IMediaSeeking)this.graphBuilder;
this.mediaPosition = (IMediaPosition)this.graphBuilder;
this.videoWindow = this.graphBuilder as IVideoWindow;
this.basicVideo = this.graphBuilder as IBasicVideo;
hr = this.mediaEventEx.SetNotifyWindow(myOwnerPanelHandle.Handle, WMGraphNotify, IntPtr.Zero);
DsError.ThrowExceptionForHR(hr);
hr = this.videoWindow.put_Owner(myOwnerPanelHandle.Handle);
DsError.ThrowExceptionForHR(hr);
this.videoWindow.put_AutoShow(OABool.False);
hr = this.videoWindow.put_WindowStyle(WindowStyle.Child | WindowStyle.ClipSiblings | WindowStyle.ClipChildren);
DsError.ThrowExceptionForHR(hr);
hr = InitVideoWindow(1, 1);
DsError.ThrowExceptionForHR(hr);
#if DEBUG
rot = new DsROTEntry(this.graphBuilder);
#endif
hr = this.mediaControl.Run();
DsError.ThrowExceptionForHR(hr);
hr = this.mediaControl.Pause();
DsError.ThrowExceptionForHR(hr);
hr = mediaPosition.get_Duration(out Duration);
DsError.ThrowExceptionForHR(hr);
hr = basicVideo.get_VideoHeight(out pVideoHeight);
DsError.ThrowExceptionForHR(hr);
hr = basicVideo.get_VideoWidth(out pVideoWidth);
DsError.ThrowExceptionForHR(hr);
}
|
|
|
|
|
What is not working? A null renderer just discards all the input it receives (so nothing is drawn to the screen).
|
|
|
|
|
It's drawn into ActiveMovie window how to hide this window ?
|
|
|
|
|
I'm not the best person to help you with this, I'm afraid, but:
You're going to have to replace the video renderer with the null renderer.
Maybe this article can help you? http://msdn.microsoft.com/en-us/library/dd407299(v=vs.85).aspx[^]
It implies that if you first create an instance of the null renderer, add it to the graph and then call RenderFile that the graph builder will use the null renderer instead of the default one.
Otherwise, you are going to have to examine the built graph and search for the video renderer and replace that.
|
|
|
|
|
Thank you so much for your help !! It's working now !
|
|
|
|
|
Hi All,
I've started working on a new project which uses PRISM to create all of the modules. We also use Castle as the container. My question is I want to be able to deep link between views in the same module. All the examples on the web only show how to deep link between modules I.e. implement INavigationAware, register the view with the region manager and then if the IsNavigationTarget returns true then your pretty much done.
But when I try to do this in the same module it doesn't work as the region manager wants to look in the module catalog for a specific view which obviously doesn't exist as its just a list of modules.
In my example the module is called Search which is registered in the Bootstrapper with a ModuleInfo. ModuleName is set to "Search". I then register all of the Views/ViewModels with the container in the IWindsorInstaller implementation. In my Initialize method I then register the root view and the subsequent results view (which is were I want to navigate to) with the RegionManager.
Then I think I should be set to go, only thing is I haven't set a URI anywhere for the results view unless its the view name (tried that didn't work). So I guess I need to do that somewhere but not sure were? Then once this is done I think I should be all set to go aslong as the Results view implements INavigationAware which it does but at the moment it never gets this far!
Any help/pointers appreciated!
Phil
|
|
|
|
|
So I recently began experimenting with Entity Framework. And one of the bigger specific topics I have encountered is the Repository pattern. In which case(s) is it appropriate to implement the Repository pattern? Is it generally a good practice to use it in every situation? Or are there only certain scenarios in which it will be beneficial and others in which it is a waste of time?
djj55: Nice but may have a permission problem
Pete O'Hanlon: He has my permission to run it.
|
|
|
|
|
When you have an entity in your framework that needs to repose I guess.
|
|
|
|
|
All of the data I work with almost ALWAYS gets retrieved from a database and the connection is no longer needed, until data is retrieved again which is not too often. So would this benefit from a repository?
djj55: Nice but may have a permission problem
Pete O'Hanlon: He has my permission to run it.
|
|
|
|
|
I would have thought that the database was the repository, but what do I know?
|
|
|
|
|
I haven't used Repository as an Official Pattern (TM), so this might be completely barking up the wrong tree. Feel free to ignore if so (actually, better to comment and tell me :P). But as I understand it, a repository is essentially a local (i.e. in memory within the client process) cache of entities which have been loaded from the database. It's also a writeable cache (so you can save entities to it, and some time later, they get fully persisted).
They are useful when the data is:
- For a reading repository:
- Non volatile, i.e. they don't change very often. A cache that has to refresh every request is no use.
- Large. You still have to check whether there's been a change (usually involves adding more to the data source and a small amount of overhead), so the cached data needs to be large enough that the request for 'has it changed' isn't as much effort as just getting the data would be. Note that this generally means that you can't cache at the single entity (i.e. one row) level, as finding out if a row changed is as heavy as just returning the row, unless the row is very large and bandwidth to the database is an issue. (If you don't care if your information is out of date, you don't need to ask the DB and you can ignore this. But usually you do care.)
- For a writable repository:
- Not shared between processes, or not synchronisation-critical. There's no point having a write-back cache if you have to invalidate it immediately to synchronise the data with another process. However, if you are updating things frequently, and don't need every change to commit to the database immediately, you can save a lot of database updates.
They're also useful if database access is expensive, and your client is the only consumer (so you don't need to worry about synchronisation and changes occuring from elsewhere while you're running). In that case you can use a repository as a local cache of the database and only ever have to read any particular item once.
|
|
|
|
|
Thanks for the explanation. If someone can comment and verify this as an acceptable and valid explanation then I will go with it. It makes plenty of sense to me. Thanks.
djj55: Nice but may have a permission problem
Pete O'Hanlon: He has my permission to run it.
|
|
|
|