Scheduler mess my program up ????

KeldSor 351 Reputation points
2022-02-01T15:22:11.79+00:00

I have build a C# console program for backing up my Outlook mail system and it should run every sunday af 12:00 oclock and it has done so for years.

In essence what it does is 1) Stops Outlook, 2) copy the OST-file and 3) Starts Outlook again - that's it !

SOMETIMES though it will NOT start Outlook again and I have found out that WHEN it's the case it's because a kind of 'hidden instance' of Outlook is running, I can't see any Outlook on the screen, but the sort of 'hidden process' is visible in the Tastmanager.

The whole backup job is managed in the Windows Scheduler so I tried to investigate a little and found out that IF I start the job by simply entering the commend in a CMD-window it runs nicely !

Only when managede by the Scheduler it sometimes makes this spooky hidden instance of Outlook and then it wont start Outlook again.

Why is it so ?

Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,795 questions
{count} votes

3 answers

Sort by: Most helpful
  1. KeldSor 351 Reputation points
    2022-02-02T07:49:31.053+00:00

    @Hui Liu-MSFT

    THX for your offer, but I think it's way too complex a setup and lots of setting up parameters to explain for you to get it to work if you should have the whole code.

    Not that I don't want to share my code, but it's way too special and I think the 'explaining' will be around YOU to understand what I mean in my explaining and code ;-)
    My first language is DANISH so detailed explaining in english/american will be a little wierd I think ;-)

    I think I hvae isolated the problems to the way I STOP and START Outlook and I have tried different codes for that too:

    Here is my code for STOPPING - in the first place I just used KILL() (why not go for the heart !), then CloseMainWindow() and then I use a "nicer" method - told by someone in a C# Forum out there:

            private static Boolean StopExecutionOf(String r)  
            {  
                foreach (Process clsProcess in Process.GetProcesses())  
                {  
                    if (clsProcess.ProcessName.ToLower() == r.ToLower())  
                    {  
                        try  
                        {  
                            clsProcess.Kill();    // CloseMainWindow();  
                        }  
                        catch  
                        {  
                            return false;  
                        }  
                        return true;  
                    }  
                }  
                return false;  
            }  
            private static void EndProcessTree(string imageName)  
            {  
            // Just some CUT/PASTE from out there !!!  
            // but it 'stops' the process !  
                Process.Start(new ProcessStartInfo  
                {  
                    FileName = "taskkill",  
                    Arguments = $"/im {imageName} /f /t",  
                    CreateNoWindow = true,  
                    UseShellExecute = false  
                }).WaitForExit();  
            }  
    

    Here are my code for STARTing Outlook again:

                            ProcessStartInfo startInfo = new ProcessStartInfo("Outlook.exe")  
                            {  
                                WindowStyle = ProcessWindowStyle.Minimized  
                            };  
                            Process.Start(startInfo);  
    

    Hope this can tell you something I don't see - it's SO annoying not to have it working with Scheduler - I think Scheduler was made for just such tasks - right ?


  2. KeldSor 351 Reputation points
    2022-02-04T11:35:39.103+00:00

    I have 'solved' the problem by making a good old BATCH-file with my commend and manage THIS batch-file with Scheduler - it works !

    I don't want to vaste more time here !

    (How do I mark this thread as SOLVED ?)


  3. KeldSor 351 Reputation points
    2022-02-07T08:43:32.227+00:00

    I have NO such "Accept Answer" to click on !

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.