none
How to run multiple instance of C# console application simultaneously? RRS feed

  • Question

  • Hi Guys,

    I've a C# console application, I need to create four instance of the application and have to start all four at once. It throws an error when all of them starts at the same time, If I create four sub folders and schedule to run all at once it works fine.

    When I try to run them simultaneously from the same location it throws error, any suggestions?!

    Thanks!!

     

     

     

     


    Regards, Jagadeesan Kandasamy
    Tuesday, August 10, 2010 1:59 AM

Answers

  • The most likely reason for the application to fail when you run it simultaneously is the lack of availability of a resource being used by the application. Either it is trying to write to a file, opening a socket on a predefined port, writing a registry entry or any other similar action that requires an exclusive lock on a resource. The first application instance to get the lock continues it's work, the others fail when they stumble upon a locked resource.
    -- Blog: http://geeklyeverafter.blogspot.com/
    • Marked as answer by SamAgain Monday, August 23, 2010 6:40 AM
    Friday, August 20, 2010 9:22 AM
  • > throws an error

    Please post the complete error message and stack trace.

    (My guess is that you might be writing to a file in the same folder, hence only one process can open the file at a time.)

     

    • Marked as answer by SamAgain Monday, August 23, 2010 6:41 AM
    Tuesday, August 10, 2010 2:42 AM

All replies

  • > throws an error

    Please post the complete error message and stack trace.

    (My guess is that you might be writing to a file in the same folder, hence only one process can open the file at a time.)

     

    • Marked as answer by SamAgain Monday, August 23, 2010 6:41 AM
    Tuesday, August 10, 2010 2:42 AM
  • I'm not writing into files, it shows the below error message..

    "Application had generated an exception that could not be handled. Processid=0x188(392), thread Id = 0x102c(4140)."

    If I view in the VS debugger, it shows error at the main() method, FYI this application runs simultaneously if i start them with 1 sec gap, this throws the above error message when all of starts in the same time...


    Regards, Jagadeesan Kandasamy
    Tuesday, August 10, 2010 3:13 AM
  • Hi,

    Thanks for your post.

    How did you start that application simutaneously? Could post some code snippets about how you launching that application? What did that application do at the start? Please consider adding some try/cactch block to see what exactly the exception is.


    Please mark the right answer at right time.
    Thanks,
    Sam
    Tuesday, August 17, 2010 9:42 AM
  • Hi,

    I am writing to check the status of the thread. How is the problem going on?


    Please mark the right answer at right time.
    Thanks,
    Sam
    Thursday, August 19, 2010 3:39 AM
  • The most likely reason for the application to fail when you run it simultaneously is the lack of availability of a resource being used by the application. Either it is trying to write to a file, opening a socket on a predefined port, writing a registry entry or any other similar action that requires an exclusive lock on a resource. The first application instance to get the lock continues it's work, the others fail when they stumble upon a locked resource.
    -- Blog: http://geeklyeverafter.blogspot.com/
    • Marked as answer by SamAgain Monday, August 23, 2010 6:40 AM
    Friday, August 20, 2010 9:22 AM