0

i have console application and web application. i am calling the main program of console from web application like this

Web

 public void RunconsoleApplication(string CanpaignId) {
        // Get the file path of your Application (exe)
        string filePath = @"E:/ConsoleApplication1/ConsoleApplication1/bin/Debug/ConsoleApplication1.exe";

        System.Diagnostics.ProcessStartInfo info = new System.Diagnostics.ProcessStartInfo(filePath, CanpaignId);

        System.Diagnostics.Process p = System.Diagnostics.Process.Start(info);
        p.Start();
    }

Console

Class program {
    static void Main(string[] args) {
        Console.WriteLine("start without arg");
        if (args.Length > 0) {  
            Program p = new Program();
            // This is another function in the class, not copied here
            p.CreateCanpaign(Convert.ToInt64(args[0]));                

            Console.WriteLine("stop");             
        } 
    }
}

now can someone explain why this function 'CreateCanpaign(a)' is called twice. i am new to console applications. thanks in advance.

Simon Dugré
  • 17,980
  • 11
  • 57
  • 73
Dolly Dar
  • 97
  • 1
  • 12

1 Answers1

3

Because of these two lines, you are starting it twice

System.Diagnostics.Process p = System.Diagnostics.Process.Start(info);
p.Start();

Remove p.Start();

Habib
  • 219,104
  • 29
  • 407
  • 436
  • so p.start() should not be included?? – Dolly Dar Jun 28 '12 at 07:14
  • ahh.. i know that was simple thing to ask.. but sometimes these little things are difficult to find out.. thankyou very much .. :) – Dolly Dar Jun 28 '12 at 07:19
  • plz can you tell me one thing more.. i am calling this function as a user. how can i call it as an administrator with username and password.. i have tried some code but it is not working.. – Dolly Dar Jun 28 '12 at 07:21
  • @DollyDar, see this thread http://stackoverflow.com/questions/2532769/how-to-start-a-process-as-administrator-mode-in-c-sharp – Habib Jun 28 '12 at 07:25