Results 1 to 4 of 4

Thread: C# Code to Shutdown Any Excel Process Running Longer Than 1 Minute

  1. #1

    Thread Starter
    Hyperactive Member Vladamir's Avatar
    Join Date
    Feb 2012
    Location
    Miami, FL
    Posts
    486

    C# Code to Shutdown Any Excel Process Running Longer Than 1 Minute

    I need a method to add at the beginning of my project that will check and see if any Excel processes have been running longer than 1 minute and shut them down if it finds any. I have a method which shuts down all instances of Excel but I only want to kill them if they've neen running longer than 1 minute.

  2. #2
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,711

    Re: C# Code to Shutdown Any Excel Process Running Longer Than 1 Minute

    What you should so is:

    1. Create a new thread
    2. Create an infinite loop on that thread
    3. Continuously check if any Excel program opens
    4. If an Excel program opens, create a new timer and set it's interval to 1 minute
    5. After that minute is up, check if the Excel program is still open. If it is, then close it.


    Here are some material on the different subjects mentioned:
    Threading
    Threading Tutorial - MSDN - Link Here
    Threading (C# and Visual Basic.Net) - MSDN - Link Here

    Infinite Loop
    How do I create an infinite loop - MSDN C# Forums - Link Here
    C# While - Dot Net Perls - Link Here

    Excel
    Get instance of Excel application with C# by Handle - Stack Overflow Forums - Link Here
    How can I open the current instance of Excel from my application? - Stack Overflow Forums - Link Here

    Processes
    How to terminate a process in c# - MSDN C# Forums - Link Here
    Process.Close Method - MSDN - Link Here
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  3. #3
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    6,597

    Re: C# Code to Shutdown Any Excel Process Running Longer Than 1 Minute

    1minute even if someone is using it?If not then you can also add this to your thoughs if you need the excel to be idle.
    http://www.vbforums.com/showthread.p...77#post4267177
    (It's in VB but i bleed these days with C# and i should share the opposite bleeding )
    ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
    πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·

  4. #4

    Thread Starter
    Hyperactive Member Vladamir's Avatar
    Join Date
    Feb 2012
    Location
    Miami, FL
    Posts
    486

    Re: C# Code to Shutdown Any Excel Process Running Longer Than 1 Minute

    saptor, yes, this is an automated process and if an Excel instance has been running longer than 1 minute then it's definitely in need of whacking. And yes, I too was a VB.NET man but they tied me down and forced me to start learning C#. Oh well, could be worse. Could be raining.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width