AHF
AHF

Reputation: 1072

Program breaks in c# on process class

private void button1_Click(object sender, EventArgs e)
        {
            if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                string fileName = openFileDialog1.FileName;

                ProcessStartInfo info = new ProcessStartInfo();
                info.WindowStyle = ProcessWindowStyle.Hidden;
                info.FileName = "WK01.exe";
                info.Arguments = "WK01.exe";
                info.Arguments = fileName;
                Process p = new Process();

                p.StartInfo = info;
                p.Start();
                p.WaitForExit();


            }
        }

When I run this code , this code break on p.Start(); , as my WK01.exe project contain 2 arguments , one is its path and second is what I give to it like picture or anything , when I run it and press the button it ask me for picking the file when I pick the file it break program on p.Start();

Upvotes: 0

Views: 155

Answers (2)

Agat
Agat

Reputation: 4779

That's because there is no wk01.exe executable file in your bin/debug (or bin/release) folder.

If you want, you can add it to your project files (even as a reference) and mark as "Copy to Output directory = Copy always" to do that automatically.

Upvotes: 1

Thilina H
Thilina H

Reputation: 5810

info.Arguments you have updated twice.So its only take the last updated value.if you want to pass 2 argument you can do it as follows.

info.Arguments = "WK01.exe "+fileName;

Example Here

Upvotes: 1

Related Questions