Bonjour;
jai créer un Thread qui met a jour une listView, et a l'execution il y'a une exception :
An unhandled exception of type 'System.InvalidOperationException' occurred in System.Windows.Forms.dll
Additional information: Cross-thread operation not valid: Control 'listView2' accessed from a thread other than the thread it was created on.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27 delegate void DelegateThreadTask(); . . . private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) { Threading::Thread(gcnew ThreadStart(this, &Form1::Traitement)); t->Start(); } . . . void Traitement( ) { while(true) {ThreadTask();Thread::Sleep(100);} } void ThreadTask() {listView2->Items->Add("zezeze"); DelegateThreadTask ^ er = gcnew DelegateThreadTask(this, &Form1::ThreadTask); Invoke(er); }
comment écrire dans la listView??
Merci énormement
Partager