Autor Beitrag
Cäptin Pommes
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 142
Erhaltene Danke: 2



BeitragVerfasst: Di 07.02.12 13:13 
hi,
ich habe eine Methode die in einem eigenen Thread ablaufen soll, die Methode wird bei einem MouseDown event ausgelöst.
das problem ist er muss auf ein paar elemente im GUI-Thread zugreifen und das mag er nich so ganz ^^

ich hab bereits rausgefunden das ich wohl Dispatcher und Invoke brauche ... jedoch weiss ich nich wirklich wie ich das auf mein problem anwenden soll :/

z.B. wird bei meiner methode (die im eigenen thread ablaufen soll) am anfang geguckt ob ein Radiobutton gecheckt ist oder nich ... wie kann ich das jetzt dadrauf anwenden?
Cäptin Pommes Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 142
Erhaltene Danke: 2



BeitragVerfasst: Di 07.02.12 13:35 
ok hab ne lösung gefunden :D ... aber keine ahnung ob das die beste ist^^

ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
private delegate void threadDelegate();
.
.
.
private void picSaveBtn_MouseDown(object sender, MouseButtonEventArgs e)
        {
            if (e.ChangedButton == MouseButton.Left)
            {
                threadDelegate td = new threadDelegate(SavePicsLocal);

                ThreadStart start = delegate() { Dispatcher.BeginInvoke(td, null); };
                Thread thread = new Thread(start);
                thread.Start();
            }
        }

private void SavePicsLocal()
        {...}
Kha
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 3803
Erhaltene Danke: 176

Arch Linux
Python, C, C++ (vim)
BeitragVerfasst: Di 07.02.12 14:04 
Damit hast du den Backgroundthread ad absurdum geführt ;) .
Wenn es um das Auslesen und nicht um das Setzen von GUI-Daten geht, sollte das vor dem Threadstart geschehen und dann dem Thread direkt übergeben werden.

_________________
>λ=
Cäptin Pommes Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 142
Erhaltene Danke: 2



BeitragVerfasst: Di 07.02.12 14:18 
ähhh sry, ich weiss nich genau was du meinst ^^
kannst du mir das kurz an meinem beispiel zeigen?