|
Are you running in a debugger? They will often notify you of exceptions even inside a catch. If you run this application on its own that should work, though it has a couple of issues (you will create the file if it doesn't exist, and you should be catching the specific exception you are looking for if you are just trying to find if the file is locked by another app).
|
|
|
|
|
Thanks a lot!
I runned the app by its own as you told, and that worked!
modified on Thursday, April 21, 2011 5:38 AM
|
|
|
|
|
Welcome.
You should be able to press Continue or similar (it's F5 in the debuggers I know) when you get an exception breakpoint inside a try when running in the debugger, by the way. You can also set your debugger not to notify you of caught exceptions.
|
|
|
|
|
I use this function,
private static bool FileInUse(string path)
{
FileInfo file = new FileInfo(path);
FileStream stream = null;
try
{
stream = file.Open(FileMode.Open, FileAccess.ReadWrite, FileShare.None);
}
catch (IOException ex)
{
return true;
}
finally
{
if (stream != null)
stream.Close();
}
return false;
}
although it will only return true if the file is Locked by another application(or yours). If the other application has opened the file without locking it will return false. You should be careful with your implementation as if the file is not found it would create one.
...and I have extensive experience writing computer code, including OIC, BTW, BRB, IMHO, LMAO, ROFL, TTYL.....
|
|
|
|
|
Thanks for the answer.
I will change "FileMode.OpenOrCreate" to "FileMode.Open" as you said.
The oly problem that was causing the program crash was I was running it in debug mode.
I have runned it by its own as BobJanova advised, and now it is working fine.
|
|
|
|
|
Unfortunately, your method and the method below does not work. If you place a lock on the file you have to wait for the O.S. to release the file. Thus a call FileInUse that returns true can still fail on the file open. The only way is to open the file and lock the file and return that lock.
|
|
|
|
|
Does anyone know how to get an attached database to store data permanet?, and if so please help me out with some links..
|
|
|
|
|
Why don't you let us know what database you are using, and what do you mean by permanent. Is the database losing data when you close the app, or when you install updates to the application or when? When asking a question you need to be pretty specific as to what the problem is and you might get more help.
...and I have extensive experience writing computer code, including OIC, BTW, BRB, IMHO, LMAO, ROFL, TTYL.....
|
|
|
|
|
But I get the data from the database and make changes and when I reopen the application the changes are not there, they always were when I used Access why doesn't the information stay in the database, I type it into the form!
[note the joke icon]
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Wayne the database is loosing data when ever i close the application, and m using vstudio 2008 and sql2005
|
|
|
|
|
The reason that it's doing this is because you have a master version in your solution, and it is set to be copied to the output directory whenever you build the application. This means that you are making changes to your data when the app is running and then losing them when the master overwrites it. Take a look at the Copy to output directory property on the local database file.
|
|
|
|
|
Could you provide code? Are you actually sure that the data is being "stored" in your SQL tables. My theory is that it is not writing to the DB. Can you post your code where you write to the DB?
Craigslist Troll: litaly@comcast.net
"I have a theory that the truth is never told during the nine-to-five hours. "
— Hunter S. Thompson
|
|
|
|
|
Hi all,
I have developed an application in c# and made the setup and deployment.
But the problem is that in any system when i install my application i want to display my application name when you right click on any file or folder.
For example when you install WinZip and the right click on any file you see a option Add to Winzip,...etc.
Similar function i want to do for my application.
How can i do it ?
Thanks in advance.
|
|
|
|
|
Take a look at the answer by Tarakeshwar Reddy to the question just 4 below yours.
Amazing what a bit of reading will get you.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
It is not the same question. Associating your app with an extension and extending the context menu are quite different.
|
|
|
|
|
For every file and folder it is easy: see this article[^].
If you want it only to appear for some, then you need to write a shell extension, and due to architectural issues with in-process extensions, you should only do so in .Net 4. See this article on MSDN[^].
|
|
|
|
|
Use the VS 2005 and DB is postgreSQL,now want to run the app on the linux platform.
and the DB deploy in another machine which OS is Windows Server 2003.
what should i do?
thanks in advance.
|
|
|
|
|
Your question is very unclear, but looking at the subject you want to deploy a C# application on a Linux machine. In that case, look at Mono[^].
Typical n-tiered architecture:
DB <-> Junk(0) <-> ... <-> Junk(n-1) <-> Pretty
|
|
|
|
|
Install Mono and Start with "Hello World!"[^] Program
- Regards - J O N
A good thing is a bad thing if it keeps you from the best thing. - Dr. Adrian Rogers
|
|
|
|
|
Thank you for your reply.
|
|
|
|
|
Hi ,
I started to learn LINQ but I have some questions to be clear.
1- In ADO.NET we have Connected Model and Disconnected Model ( LINQ TO DataSet ) So What is the same in Linq for Connected Model ?
2- LINQ to sql deal only with sql server and I'm try to work with other providers with LINQ to Entity but when I drag and Drop access table it said that it's not support type ?
|
|
|
|
|
This might be a really dumb question, but why didn't you post this in the LINQ forum?
Software rusts. Simon Stephenson, ca 1994.
|
|
|
|
|
|
Hi, i am doing some kind of simulation for a fuzzy logic controller, so i created the ".fis" file using MATLAB, and i want to use it in my c# project is there any way to do it.
thanks
|
|
|
|
|
Check if Matlab has a managed interface, a COM interface or a DLL interop that you can use from C#. You can press Search in Google as well as the next person.
|
|
|
|