Moin Leute.
Ich möchte per
Spoiler anzeigen
Während der Laufzeit kommt bei
Hat jemand von Euch eine Lösung dazu?
Danke.
================================================================
Geklärt.
In
Also - dies funktioniert:
Spoiler anzeigen
Ich möchte per
(Begin)Invoke
einen Parameter string[]
bzw. List<string>
an eine entsprechende Prozedur übergeben:C#-Quellcode
- using System;
- using System.Collections.Generic;
- using System.Windows.Forms;
- // Form mit 3 Button
- namespace WindowsFormsApp1
- {
- public partial class MainForm : Form
- {
- // TODO: Ggf. den Pfad Anpassen
- private const string TempDir = "D:\\Temp\\";
- public MainForm()
- {
- this.InitializeComponent();
- }
- private void Button1_Click(object sender, EventArgs e)
- {
- string[] files = System.IO.Directory.GetFiles(TempDir);
- Action<string[]> action = new Action<string[]>(this.Test);
- this.Invoke(action, files);
- //this.BeginInvoke(action, files);
- }
- private void Button2_Click(object sender, EventArgs e)
- {
- string[] files = System.IO.Directory.GetFiles(TempDir);
- List<string> ll = new List<string>(files);
- Action<List<string>> action = new Action<List<string>>(this.Test2);
- this.Invoke(action, files);
- //this.BeginInvoke(action, files);
- }
- private void Button3_Click(object sender, EventArgs e)
- {
- Action<string> action = new Action<string>(this.Test3);
- this.BeginInvoke(action, "meldung");
- }
- private void Test(string[] files)
- {
- MessageBox.Show(files.Length.ToString());
- }
- public void Test2(List<string> files)
- {
- MessageBox.Show(files.Count.ToString());
- }
- public void Test3(string meldung)
- {
- MessageBox.Show(meldung);
- }
- }
- }
string[]
und List<string>
folgende Exception:Hat jemand von Euch eine Lösung dazu?
Danke.
================================================================
Geklärt.
In
Button2_Click()
habe ich fälschlicherweise ein Array übergeben, während eine List<> empfangen wird, hier hat wohl der Compiler eine automatische Konvertierung vorgenommen.Also - dies funktioniert:
C#-Quellcode
- using System;
- using System.Collections.Generic;
- using System.Windows.Forms;
- namespace WindowsFormsApp1
- {
- public partial class MainForm : Form
- {
- // TODO: Ggf. den Pfad Anpassen
- private const string TempDir = "D:\\Temp\\";
- public MainForm()
- {
- this.InitializeComponent();
- }
- private void Button2_Click(object sender, EventArgs e)
- {
- string[] files = System.IO.Directory.GetFiles(TempDir);
- List<string> ll = new List<string>(files);
- Action<List<string>> action = new Action<List<string>>(this.Test2);
- //this.Invoke(action, ll);
- this.BeginInvoke(action, files);
- }
- public void Test2(List<string> files)
- {
- MessageBox.Show(files.Count.ToString());
- }
- }
- }
Falls Du diesen Code kopierst, achte auf die C&P-Bremse.
Jede einzelne Zeile Deines Programms, die Du nicht explizit getestet hast, ist falsch
Ein guter .NET-Snippetkonverter (der ist verfügbar).
Programmierfragen über PN / Konversation werden ignoriert!
Jede einzelne Zeile Deines Programms, die Du nicht explizit getestet hast, ist falsch
Ein guter .NET-Snippetkonverter (der ist verfügbar).
Programmierfragen über PN / Konversation werden ignoriert!
Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von „RodFromGermany“ ()