[c#] Frage zu Thread's / Threading

07/17/2013 13:27 .Stefan#31
Quote:
Originally Posted by 'Aleo View Post
Code:
void ChangeText(Label Control, string text)
        {
            Control.Text = text;
        }
Wäre eine Möglichkeit in C#.
Quote:
Originally Posted by Shawak View Post
Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Threading;

namespace ui_threading
{

    public partial class Form1 : Form
    {

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            System.Threading.Tasks.Task.Factory.StartNew(() =>
            {
                 this.Invoke(() =>
                 {
                        Label1.Text = "Text1";
                        Thread.Sleep(5000);
                        Label1.Text = "Text2";
                 });
            });
        }
    }
}
Sollte funktionieren

Ansonsten;
Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Threading;

namespace ui_threading
{

    public partial class Form1 : Form
    {

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            System.Threading.Tasks.Task.Factory.StartNew(() =>
            {
                 this.Invoke(() {  Label1.Text = "Text1"; });
                 Thread.Sleep(5000);
                 this.Invoke(() {  Label1.Text = "Text2"; });
            });
        }
    }
}
Lg
Danke allen, die mir geholen haben. Das war genau das, was ich gesucht habe. Aleo hat mir die 2. Frage sehr gut beantwortet und Shawak die 1. Frage. Danke :)