Autor Beitrag
Goordon
Hält's aus hier
Beiträge: 10



BeitragVerfasst: Mi 28.01.09 23:44 
Guten Abend

Ich habe ein problem mit folgender Methode:

ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
        void ReadAndRun()
        {
            FileInfo file = new FileInfo("run.ini");
            StreamReader stRead = file.OpenText();
            while (!stRead.EndOfStream)
            {
                listBox1.Items.Add(stRead.ReadLine());
            }
            for (int i = 0; i < listBox1.Items.Count; i++)
            {
                System.Diagnostics.Process.Start(listBox1.Items[i]);
            }
        }


Folgendes problem ergibt sich: ( Ich möchte eine Liste von Programmen aus der "run.ini" ausführen )

Fehler 1 Die beste Übereinstimmung für die überladene System.Diagnostics.Process.Start(System.Diagnostics.ProcessStartInfo)-Methode hat einige ungültige Argumente.

Fehler 2 1-Argument: kann nicht von "object" in "System.Diagnostics.ProcessStartInfo" konvertiert werden.

Hat jemand eine idee?


Moderiert von user profile iconChristian S.: Topic aus WinForms verschoben am Mi 28.01.2009 um 22:47
Christian S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: Mi 28.01.09 23:48 
Die Items einer ListBox sind vom Typ Object, es gibt aber keine Process.Start-Methode, welche einen solchen Parameter nimmt.

_________________
Zwei Worte werden Dir im Leben viele Türen öffnen - "ziehen" und "drücken".
danielf
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 1012
Erhaltene Danke: 24

Windows XP
C#, Visual Studio
BeitragVerfasst: Do 29.01.09 10:45 
Hallo,

was Christian meinst ist, dass du nicht listBox1.Items[i] der Start-Methode übergeben kannst, sondern einen String. In deinem Fall wäre das dann listBox1.Items[i].Text.

ausblenden C#
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
            List<Process> processList = new List<Process>();

            foreach (ListViewItem lvi in this.listCommands.Items)
            {
                Process p = new Process();
                p.StartInfo.UseShellExecute = false;
                p.StartInfo.FileName = lvi.Text;

                try
                {
                    p.Start();
                    processList.Add(p);
                }
                catch (Exception exception)
                {
                    MessageBox.Show(exception.Message);
                }
            }


Moderiert von user profile iconKha: Code- durch C#-Tags ersetzt
Kha
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 3803
Erhaltene Danke: 176

Arch Linux
Python, C, C++ (vim)
BeitragVerfasst: Do 29.01.09 13:29 
user profile icondanielf hat folgendes geschrieben Zum zitierten Posting springen:
was Christian meinst ist, dass du nicht listBox1.Items[i] der Start-Methode übergeben kannst, sondern einen String. In deinem Fall wäre das dann listBox1.Items[i].Text.
System.Object besitzt keine Text-Property; dein Beispiel benutzt eine ListView. Benötigt wird also ein Cast von Object auf String.

_________________
>λ=