ksor
Active member
- Joined
- Jul 4, 2019
- Messages
- 33
- Programming Experience
- 10+
I have a console program doing automatic backup of my mailsystem every sunday managed by Windows Scheduler.
My program can do a lot of different thing, but the issue here is STOPPING, copying the OST-file and then STARTING Outlook again.
I use the following code snippet:
Outlook is not allways stopping - if I take a taskmaneger I can see Outlook is running - but else I can't see it on the screen !
WHEN Outlook is left 'running' - sort of hidden - THEN my command to start it again fails !
I have to manually stop the 'running Outlook' and then start Outlook again.
Here are the code I'm using for STOP of Outlook:
Here are the code I'm using for testing for a running Outlook:
WHY is Outlook SOMETIMES left running as 'sort of hidden' process I HAVE to kill via the Taskmaneger ?
My program can do a lot of different thing, but the issue here is STOPPING, copying the OST-file and then STARTING Outlook again.
I use the following code snippet:
C#:
startInfo.WindowStyle = ProcessWindowStyle.Minimized;
Process.Start(startInfo);
}
else if (args[0].ToUpper()=="GO") {
if (ThisIsRunning("Outlook")) {
StopExecutionOf("Outlook"); <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< not always working
}
// Her testes på OM ALLE parametre ER angivet !
if ((Properties.Settings.Default.Datafil.ToString()=="") |
(Properties.Settings.Default.SikkMappe.ToString()=="") |
(Properties.Settings.Default.Modtager.ToString()=="") |
(Properties.Settings.Default.Bruger.ToString()=="") |
(Properties.Settings.Default.Password.ToString()=="")){
handleParams();
}
else{
File.Copy(Properties.Settings.Default.Datafil.ToString(), Properties.Settings.Default.SikkMappe.ToString(), true);
sendMail(Properties.Settings.Default.Modtager.ToString(), txtSuccess);
int milliseconds = 1000;
System.Threading.Thread.Sleep(milliseconds);
ProcessStartInfo startInfo = new ProcessStartInfo("Outlook.exe"); <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< not always working
startInfo.WindowStyle = ProcessWindowStyle.Minimized;
Process.Start(startInfo);
}
}
else {
args=null;
ShowWindow(handle, SW_SHOW);
someThingWrong();
Outlook is not allways stopping - if I take a taskmaneger I can see Outlook is running - but else I can't see it on the screen !
WHEN Outlook is left 'running' - sort of hidden - THEN my command to start it again fails !
I have to manually stop the 'running Outlook' and then start Outlook again.
Here are the code I'm using for STOP of Outlook:
C#:
private static Boolean StopExecutionOf(String r) {
foreach (Process clsProcess in Process.GetProcesses()) {
if (clsProcess.ProcessName.ToLower()==r.ToLower()) {
try {
clsProcess.Kill();
}
catch {
return false;
}
return true;
}
}
return false;
}
Here are the code I'm using for testing for a running Outlook:
C#:
private static bool ThisIsRunning(String r) {
bool Result = false;
System.Diagnostics.Process[] aProcess = System.Diagnostics.Process.GetProcesses();
for (int ProcessIndex =0; ProcessIndex < aProcess.Length; ProcessIndex++) {
if (aProcess[ProcessIndex].ProcessName.ToUpper() == r.ToUpper()) {
Result = true;
break;
}
}
return Result;
}
WHY is Outlook SOMETIMES left running as 'sort of hidden' process I HAVE to kill via the Taskmaneger ?
Last edited: