Only SHELLEXECUTE can be ensured in the STA thread. In the implementation of Process, this problem is not taken into account, so running shellexecute using the Process class may be wrong. If you can't guarantee the ApartmentState of calling Process.start, you can use the following code to avoid this question:
Using system;
Using system.threading;
Public class foo {
Public static void OpenURL () {
System.Diagnostics.Process.start (@ "http://www.google.com");
}
Public static void
Main
() {
ThreadStart OpenURLDELEGATE = New ThreadStart (foo.openurl);
Thread mythread = new thread (OpenURLDELEGATE);
Mythread.SetaPartmentState (ApartmentState.sta);
mythread.start ();
mythread.join ();
}
}
When using the Process class to open unknown type files, the error code is Win32Exception for ERROR_NO_ASSOCIATION.
Set ErrorDialog in ProcessStartInfo to display the "Open WITH" dialog:
Using system.diagnostics;
Class test {
Public static void
Main
() {
ProcessStartInfo Info = New ProcessStartInfo ();
Info.filename = "t.tt";
INFO.ERRORDIALOG = TRUE;
Process.start (Info);
}
}