Click here to Skip to main content
15,919,613 members
Home / Discussions / Managed C++/CLI
   

Managed C++/CLI

 
QuestionThread and listView Pin
abbd27-Jul-07 13:16
abbd27-Jul-07 13:16 
AnswerRe: Thread and listView Pin
Luc Pattyn27-Jul-07 13:43
sitebuilderLuc Pattyn27-Jul-07 13:43 
GeneralRe: Thread and listView Pin
Mark Salsbery27-Jul-07 14:03
Mark Salsbery27-Jul-07 14:03 
GeneralRe: Thread and listView Pin
Luc Pattyn27-Jul-07 14:06
sitebuilderLuc Pattyn27-Jul-07 14:06 
QuestionRe: Thread and listView Pin
abbd27-Jul-07 23:33
abbd27-Jul-07 23:33 
AnswerRe: Thread and listView Pin
Luc Pattyn27-Jul-07 23:49
sitebuilderLuc Pattyn27-Jul-07 23:49 
QuestionRe: Thread and listView Pin
abbd28-Jul-07 0:04
abbd28-Jul-07 0:04 
AnswerRe: Thread and listView Pin
Luc Pattyn28-Jul-07 0:21
sitebuilderLuc Pattyn28-Jul-07 0:21 
OK,

this is the problem: in Windows, each Control (such as a ListView) must be
handled by only one thread; the thread that creates the Control is the only
thread that successfully can read and write its properties, and execute its
methods. Violating this rule gives:
- on older .NET abnormal behavior, possibly a complete hangup
- on .NET 2.0 and better, by default, the exception you have got

Now typically each Control is linked somehow to another Control; a Button is
on a Form, a ListView is on a Form; clicking a Button that creates and shows
a dialog links that dialog to the original Button and Form, etc.

So normally all Controls belong to the main thread (also known as "GUI thread").

There are two ways to solve your problem:
- the easy way is have every Control be handled by the GUI thread, which
could mean, use a Forms.Timer, since that executes its Tick handler on the
GUI thread. The drawback is, if the Tick handler takes too long, your GUI
responsiveness will suffer
- use some other thread for calculating things, accessing a database, whatever,
but as soon as it needs to access a Control, let it ask the GUI thread to do
so. That can be organized by the Control.InvokeRequired property, and the
Control.Invoke or Control.BeginInvoke methods.

I suggest the latter; so read up on InvokeRequired and Invoke.
There are some good articles about it on CodeProject; my Sokoban article
shows a small example too (I used a Timers.Timer so I could demonstrate the
Invoke stuff).

Smile | :)


GeneralRe: Thread and listView Pin
abbd28-Jul-07 0:48
abbd28-Jul-07 0:48 
GeneralRe: Thread and listView Pin
Luc Pattyn28-Jul-07 1:03
sitebuilderLuc Pattyn28-Jul-07 1:03 
QuestionRe: Thread and listView Pin
abbd28-Jul-07 2:39
abbd28-Jul-07 2:39 
AnswerRe: Thread and listView Pin
Luc Pattyn28-Jul-07 3:07
sitebuilderLuc Pattyn28-Jul-07 3:07 
QuestionRe: Thread and listView Pin
abbd28-Jul-07 11:20
abbd28-Jul-07 11:20 
QuestionVersion Info in C++/CLI assemblies Pin
Bartosz Bien27-Jul-07 11:07
Bartosz Bien27-Jul-07 11:07 
GeneralRe: Version Info in C++/CLI assemblies Pin
screanjap27-Apr-08 7:41
screanjap27-Apr-08 7:41 
QuestionWhy does Font class need full qualification? Pin
BuckBrown27-Jul-07 10:28
BuckBrown27-Jul-07 10:28 
AnswerRe: Why does Font class need full qualification? Pin
Bartosz Bien27-Jul-07 10:51
Bartosz Bien27-Jul-07 10:51 
AnswerRe: Why does Font class need full qualification? Pin
Mark Salsbery27-Jul-07 12:44
Mark Salsbery27-Jul-07 12:44 
QuestionWhy do some classes need full qualification Pin
BuckBrown27-Jul-07 10:26
BuckBrown27-Jul-07 10:26 
QuestionOpenEx problem Pin
CodeMaster_0527-Jul-07 4:15
CodeMaster_0527-Jul-07 4:15 
AnswerRe: OpenEx problem Pin
Mark Salsbery27-Jul-07 7:14
Mark Salsbery27-Jul-07 7:14 
GeneralRe: OpenEx problem Pin
CodeMaster_0527-Jul-07 9:43
CodeMaster_0527-Jul-07 9:43 
GeneralRe: OpenEx problem Pin
Mark Salsbery27-Jul-07 9:49
Mark Salsbery27-Jul-07 9:49 
GeneralRe: OpenEx problem Pin
Mark Salsbery27-Jul-07 9:54
Mark Salsbery27-Jul-07 9:54 
GeneralRe: OpenEx problem Pin
CodeMaster_0527-Jul-07 10:03
CodeMaster_0527-Jul-07 10:03 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.