|
OHHHHHHHHH. I thought you were trying to determine when the process ended.
You need to set up a thread that tries to open the file access set to FileShare.None . Once it doesn't throw an exception, the file's been closed. Do something like this:
bool closed = false;
do
{
try
{
using (FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.None))
closed = true;
}
catch (Exception ex)
{
if (ex != null) {}
}
} while (!closed)
You could use a BackgroundWorker object since it can post an event when the thread has completed, and you can react to that event..45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
Hi John.
Thanks for reply.
My code :
Process proc = new Process();
proc.StartInfo.FileName = fileName;
proc.Start();
bool closed = false;
do
{
try
{
using (FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.None))
closed = true;
}
catch (Exception ex)
{
if (ex != null) {}
}
} while (!closed);
Everytime i get closed=true. So i can't detect when file closed.
My scenario is correct ?
Thanks.We are haven't bug,just temporarily undecided problems.
|
|
|
|
|
Ya know, I don't have your code, so you're going to have to do the work here.
As a test to see if the do/while loop is working, open the fie in another program (like notepad), and start your do/while loop in a test app (run it under the debugger). I gave that code from memory - you may have to tweak it a little to make it actually do what you want. Did you put the loop into a thread like I suggested?.45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
Thanks John.
Yeah , like notepad , MS Office and so many files working well.
But some files like cs , cpp files not working ?
Thanks , again for reply.We are haven't bug,just temporarily undecided problems.
|
|
|
|
|
Maybe the program that's associated with .CS files is loading the file, and then closing it right away. So, if that's the case, that would make the file itself available, but you wouldn't know if it had been changed.
Maybe you need to use a FileSystemWatcher on the .CS file to monitor it for changes until the program you ran in the process object terminates.
I'm just grasping at straws here because you haven't fully described the problem..45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
You could do this:
public void StartProcess()
{
Process proc = new Process....
proc.EnableRaisingEvents = true;
proc.Exited += new EventHandler(process_Exited);
proc.Start();
}
private void process_Exited(object sender, EventArgs e)
{
Process process = sender as Process;
} .45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
Hi.
Thanks for reply.
I was try this , but same results. I not yet know when my file closed ?We are haven't bug,just temporarily undecided problems.
|
|
|
|
|
Well, without seeing all of the related code, we can't help you..45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
Thanks for your honest to goodness answer. We are haven't bug,just temporarily undecided problems.
|
|
|
|
|
You are trying to determine when Visual Studio closes the file without Visual Studio exiting? You cannot determine that using the Process class or FileSystemWatcher, or any other external component. The only way to figure that out is to write code that talks to Visual Studio itself and ask what the currently open documents are. No, I don't know how to do that.
|
|
|
|
|
Hi there,
i have a method in the code behind, and want to call it in the onclick event of the hyperlink, can you please help
Hyperlink: read more;
Method: protected virtual void OnClick()
{
Response.Redirect("Display.aspx?myfile=Vivi");
}
thanx
|
|
|
|
|
hi,
i have to convert the docx file into html file.
using the word viewer web component using c#. please provide a link to do so
Thank You
|
|
|
|
|
Hello,
I want to submit somehow a class name to a method and inside the method i would like to create multiple instances of the submitted class. The reason is that I want to call the constructor of a another class and want to tell which other class instances should be created. How can i do that?
|
|
|
|
|
Create a public enum of say ClassTypes and pass it to the method. Apply switch to ClassTypes and generate classes as you may require.
e.g
public enum ClassType
{
ClassA,
ClassB
}
classCInstance.CreateClass(ClassType objClass)
{
switch(objClass)
{
case ClassType.ClassA:
new ClassA();
break;
case ClassType.ClassB:
new ClassB();
break;
}
}
P.S: This is just an example for your understanding.
Hope it helps
Ahsan Ullah
Senior Software Engineer
MCTS 2.0
|
|
|
|
|
Thanks, this looks good. The only disadvantage would be that I have to manage the enum and keep it up to date.
I expect to have hundrets of different classes that would be listed in the enum. Would it be possible to get all the available classes? Basically I have those classes in a separate folder in visual studio and they are all derived from the same base class which could maybe used for the search.
|
|
|
|
|
|
Thanks, that would be a solution, however it would force me to create a DLL. I would prefer to have those classes in my .exe.
|
|
|
|
|
It doesn't need to be in a DLL to create the type. That's just what the example used. I'm pretty sure you can skip the step of loading the assembly altogether if the type is in the current assembly (i.e., if it is in the current EXE).
|
|
|
|
|
I think, the Type class in .NET will help you.
You can pass the type of the class to your function and create instances using Reflection.
class YourClass
{
......
}
.....
<code>public void YourMethod(Type type)
{
}
public void AnotherMethod()
{
YourMethod(typeof(YourClass));
}
</code> Do more work
Make more mistakes
Learn more things
|
|
|
|
|
Or pass in a ConstructorInfo instead -- make the calling method do the Reflection.
|
|
|
|
|
I won't go into details, but I would like to start a command line program from a c# form app. What I have been doing is write the file with c# code and execute it. I have been successful in changing the directory (cd ....) in the batch file. What i need now is to have another command called ("make"). I would like to know how to do this with either a batch file line or with something from a FCL class.
To better illustrate my problem, here is an example of my programs batch output.
set path=%path%;C:/pspdev/bin
set PSPSDK=C:/pspdev/psp/sdk
cmd /k cd C:\pspdev\Projects\HomebewApp
|
|
|
|
|
If you want to do something in a batch (Sequence). Then write all those commands in batch file and execute it. If you want to start that batch file from a C# application.
use Process.Start
Ahsan Ullah
Senior Software Engineer
MCTS 2.0
|
|
|
|
|
Well, you don't want to do the set commands every time you run the batch file because every time you do, it appends your path change to the system path. You should check the environment variables and make sure you need to do that before doing it. As far as the "cmd" line, you can set the working directory for an app by using the Process object..45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
I need to write a regular expression to control the textbox input.
Range : 1.00 to 2.00
Please tell me how?
|
|
|
|
|
The first character would be a "1" or "2". The second character would be a period. The third and fourth characters would be "0"-"9".
|
|
|
|