|
After
danielhasdibs wrote: WordProcess = System.Diagnostics.Process.Start(psi);
add
WordProcess.StandardOutput.ReadToEnd();
Works on my system (no need for the WaitForExit method call).
For some reason the Exited event isn't raised but the HasExited property is correctly set.
This is working...
System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo();
psi.RedirectStandardOutput = true;
psi.WindowStyle = System.Diagnostics.ProcessWindowStyle.Maximized;
psi.UseShellExecute = false;
psi.Arguments = "Help.txt";
psi.FileName = "C:\\Program Files\\Microsoft Office\\Office12\\WINWORD.EXE";
System.Diagnostics.Process WordProcess = new System.Diagnostics.Process();
WordProcess.EnableRaisingEvents = true;
WordProcess = System.Diagnostics.Process.Start(psi);
WordProcess.StandardOutput.ReadToEnd();
Console.WriteLine(WordProcess.HasExited);
System.Diagnostics.Process.Start("Explorer.exe", "http://google.com");
Dave
modified on Friday, February 8, 2008 5:27 PM
|
|
|
|
|
Hi,
this code works fine on WinXP:
Process proc=Process.Start(@"C:\test.doc");
log("procName="+proc.ProcessName);
proc.WaitForExit();
log("has exited");
provided no Word process is running yet (if there is, proc is null as per MSDN documentation).
PS: I do not use any Office Assistant, I have thrown it out long ago.
IIRC there is a small app that "helps" in launching Office components, if that were to intercept
the doc extension and then launch WinWord on its own, you would not get winword in procName;
you could fix that by explicitly starting winword, with the doc name as an argument tho).
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
Process.WaitForExit(); and Process.StandardOutput.ReadToEnd(); seem to have the same result.
Any idea why the Exited event isn't fired Luc?
Dave
modified on Friday, February 8, 2008 5:44 PM
|
|
|
|
|
ReadToEnd() did not appear in the original post, nor in my only reply
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
No - I was just comenting that it appears to have the same result
Dave
|
|
|
|
|
danielhasdibs wrote: WaitForExit() does nothing
Nothing ever does "nothing". What does it do? Return immediately?
danielhasdibs wrote: System.Diagnostics.Process WordProcess = new System.Diagnostics.Process();
Why are you creating a new process here? You only throw it away in the next line where you create another new process.
danielhasdibs wrote: WordProcess = System.Diagnostics.Process.Start(psi);
You should check the return value. If a process is reused instead or starting a new, the return value is null.
Experience is the sum of all the mistakes you have done.
|
|
|
|
|
Hi
Why did you give the wait for exit time as 10000 i.e WordProcess.WaitForExit(10000);
if you want the first application to be closed and open the second one do like this
WordProcess.WaitForExit();// wait for infinite
System.Diagnostics.Process.Start(txt_websiteAddress.Text);
And about HasExited property, if any of the word document is open other than the closed document, this property will not get updated. Since Word is single process which launch different instance of editor.
Thanks
Srini
|
|
|
|
|
Hi!
I just tried this and it works as expected using this code:
ProcessStartInfo psi = new ProcessStartInfo("C:\\Document.doc");
MessageBox.Show("Starting...");
Process p = Process.Start(psi);
p.WaitForExit();
MessageBox.Show("Finished");
The second message box appears as soon as I close Word.
Does this help?
Regards,
mav
--
Black holes are the places where God divided by 0...
|
|
|
|
|
|
Ok, I don't want to be one of those jerks who finds the answer and doesn't share so I have the working code here. I don't know why this didn't work before, but it didn't, and now it does, so I'm happy.
System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo();<br />
psi.RedirectStandardOutput = true;<br />
psi.WindowStyle = System.Diagnostics.ProcessWindowStyle.Maximized;<br />
psi.UseShellExecute = false;<br />
psi.Arguments = txt_Wordfile.Text + " /n";<br />
psi.FileName = WordExe;
<br />
System.Diagnostics.Process WordProcess = new System.Diagnostics.Process();<br />
<br />
WordProcess = System.Diagnostics.Process.Start(psi);<br />
<br />
WordProcess.EnableRaisingEvents = true;<br />
while (!WordProcess.HasExited)<br />
{<br />
;<br />
}<br />
WordProcess.Kill(); <br />
<br />
<br />
System.Diagnostics.Process.Start(txt_website.Text);
Thanks everyone for your help!
|
|
|
|
|
Hello,
Just an addintional info.
As the Process class implements IDisposable you should call Dispose() to free the memory.
You could use an using-block for that reason.
using(System.Diagnostics.Process WordProcess = new System.Diagnostics.Process())
{
WordProcess = System.Diagnostics.Process.Start(psi);
...
}
I don't think there is a need to call the "Kill" method after "HasExited" is "true".
Same with "EnableRaisingEvents", only needed if you want to handle the "Exited" event.
P.S.: Strange, that WaitForExit is not working here.
All the best,
Martin
|
|
|
|
|
Hey Guys,
I am developing a simple windows mobile gps app. I have a MC35 device which has a build in GPS on port COM0.
I am having trouble accessing that port to get the GPS data.
My code looks like this
SerialPort port = new SerialPort("COM0", 9600, Parity.None, 8, StopBits.One);
port.Open();
I get an IO Exception at the port.Open();
No other application is using this port.
When I go into Google Map GPS works fine.
|
|
|
|
|
Simerjots,
Paste the IO Exception here...
Regards,
Gareth.
|
|
|
|
|
Thanks for the reply Gareth.
All the Exception say is IOException.
Also no details avaible.
|
|
|
|
|
at System.IO.Ports.SerialStream.WinIOError(Int32 errorCode, String str)
at System.IO.Ports.SerialStream..ctor(String portName, Int32 baudRate, Parity parity, Int32 dataBits, StopBits stopBits, Int32 readTimeout, Int32 writeTimeout, Handshake handshake, Boolean dtrEnable, Boolean rtsEnable, Boolean discardNull, Byte parityReplace)
at System.IO.Ports.SerialPort.Open()
at SmartDeviceProject2.Form1.SendSampleData()
at SmartDeviceProject2.Form1..ctor()
at SmartDeviceProject2.Program.Main()
|
|
|
|
|
|
Please delete this idiot from the site. It's gotten beyond annoying at this point.
|
|
|
|
|
hey..... what do you want, i saw all your messages, its like irritating, please dont spoil the name of your home country and people. try to be polite in asking question as well in answering question.
Srini
|
|
|
|
|
I'm wondering how to implement an auto-upgrading system for a windows mobile (C# .NET 2.0) application that works as well as ClickOnce or something similar. The app would communicate to a web service to get patch info and the actual files as well.
Does anybody know of an article that explains how to impliment an upgrade system for a mobile application?
I've read a few articles on transfering files over a web service, so that's as much of a hurdle.
|
|
|
|
|
|
JGentsch wrote: Does anybody know of an article that explains how to impliment an upgrade system for a mobile application?
Do you know about the Microsoft Patterns and Practices site[^]? It used to have a Application Updater[^] block but they have reorganized the site and the only way I can find it know is with Google. Apparently they they believe Updating Application over the network is "old news".
The patterns & practices team has decided to archive this content to allow us to streamline our latest content offerings on our main site and keep it focused on the newest, most relevant content. However, we will continue to make this content available because it is still of interest to some of our users.
led mike
|
|
|
|
|
Hi,
I just wanna know if theres a "template " control or something in VS2005. otherwise i will write an xml to change the form color. forecolor etc. I want the user to be able to change the colors from xml. I think i can do it using hex color codes.Any ideas ?
|
|
|
|
|
I have no idea what you are talking about but perhaps you are interested in the XML Configuration file support in the .NET Base Class Library which can be found in the System.Configuration namespace
led mike
|
|
|
|
|
I want to give access to users to be able to change the label.forecolor, textcolor, etc through an xml file. I was wondering if theres another way of doing it or not?
|
|
|
|
|
s3rro wrote: I want to give access to users to be able to change the label.forecolor, textcolor, etc through an xml file. I was wondering if theres another way of doing it or not?
Another way to do what? Never mind I have lost interest.
led mike
|
|
|
|