|
Hi,
What does mean
- 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
i have an exception when i use listview whith thread:
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.
Please help me de resolve this great problem,
Thank you,
|
|
|
|
|
abbd wrote: 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
That's quite correct.
And here is the explanation with the remedy:
http://www.codeproject.com/script/comments/forums.asp?msg=2155450&forumid=3785#xx2155450xx[^]
Did you read up on Control.InvokeRequired and Control.Invoke() by now ?
|
|
|
|
|
Hi,
InvokeRequired Gets a value indicating whether the caller must call an invoke method when making method calls to the control because the caller is on a different thread than the one the control was created on.
Form1 ^ob = (Form1^) obj;<br />
if(ob->progressBar1->InvokeRequired)<br />
{MessageBox::Show(I am in invoke ); <br />
ProgressBarCallback ^d = gcnew ProgressBarCallback(ThreadTask);<br />
ob->Invoke(d,gcnew array<System::Object^>{ob}); <br />
}<br />
else<br />
{<br />
MessageBox::Show(I am not in invoke );<br />
<br />
ob->listView2->Items->Add("GooD");<br />
<br />
<br />
}
He swow me always I am in invoke, thus he was in 1st thread, How i can add in listView??
Thank's
|
|
|
|
|
Hi,
I can't give you a C++ example. You need to construct a method that checks
InvokeRequired; in the "then" part use Invoke to call that same method (itself)
again (so it runs again, but this time on the GUI thread), and in the "else"
part do what needs to be done.
There are plenty examples around, mine would all be in C#.
|
|
|
|
|
I am trying to port this tutorial to a wxwidget application, with mingw32. This class generates the default context menu on windows files from explorer.
I have converted some parts successfully, but it seems mingw's api doesn't know anything about IID_IContextMenu3 and IContextMenu3 ( undeclared references bacause shobjidl.h doesn't exist on mingw32 api ).
Could someone help me to fix this ? ( or give me another way to display such context menu )
thx
carlos
|
|
|
|
|
To whom it may concern,
I want to develop a new GINA DLL and replace it with the Standard Microsoft GINA DLL. I want to use pki-based smart card for logon. I am familiar with GINA to some extent, but I want to know more. If there is any article available, please let me know. I'd appreciate it.
Regards,
Qeraati
|
|
|
|
|
Have you looked around on MSDN?
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
|
Can you even write a GINA dll using .NET code ?
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Is it possible, or would a wrapper be needed?
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
Hello,
I try this but there are a lot of error (I try to cal a method of the original form "form" but i can't do it)
public void TraitementForm1()<br />
{<br />
<br />
}<br />
<br />
public void OuvertureForm2()<br />
{<br />
form2 ^maForm2 = gcnew form2();<br />
maForm2->Owner = this;<br />
maForm2->Show();<br />
}<br />
<br />
<br />
private void ButtonOk_Click(object sender, System.EventArgs e)<br />
{<br />
Form1 ^maForm1 = safe_cast<Form1 ^>(this->Owner);<br />
maForm1->TraitementForm1();<br />
}
How to resolve this
thank you
very much
aef
|
|
|
|
|
Hello all,
Is it possible to generate .NET 3.0 assemblies with C++/CLI under VS2005, or do I need VS2008? I have installed the WPF/WWF extensions, but these seem to be C#-only. Maybe there is some trick to make C++ use .NET 3.0?
|
|
|
|
|
You should be able to create .NET 3.0 assemblies under VS2005 with C# and VB.NET. I've been doing so for a while now. You have to install the WPF/WCF/WWF extensions from Microsoft. Not sure about C++/CLI, I would imagine there would be a way to do it. MSDN any help?
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
You can just add them as references but it might be that the designers are only supported with C# :/
|
|
|
|
|
Let me add that the designer for WPF on C# Express (even with VS 2005 Standard Edition) really bites and recommend using the Expression Blend for the design part
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
if you're going to do much WPF stuff (and especially XAML) just save yourself the headache and use C#
|
|
|
|
|
Hi,
I create thred who call a methode whitch add on listView, bu unfortunately there are an Exception on execution in line listView2->Items->Add("zezeze");
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {<br />
Threading::Thread(gcnew ThreadStart(this, &Form1::Traitement));<br />
t->Start();<br />
<br />
}<br />
<br />
<br />
void Traitement( )<br />
{listView2->Items->Add("zezeze");}<br />
}
When i put MessageBox in place listView, he show me a message normusly, please Help me to resolve this great problem.
Thank you verry mutch
|
|
|
|
|
Hi,
An exception explains itself by giving a message, some additional information,
and a stack trace; if inner exceptions are present, these get explained too.
did you care to read any of that ?
would it not be useful to add it to your post, so others can see it ?
All we can do now is guess, and if we guess wrong all our efforts are lost.
|
|
|
|
|
Use The Force
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I do, if necessary.
I try the normal way first.
I bet it is an InvalidOperationException due to cross-thread violations
but dont want to waste message space, and everybody's time.
|
|
|
|
|
Hi,
can you shwou me, how a use force, an exeemple if it's possible,
thank you verry mutch.
|
|
|
|
|
I can not explain "The Force" to you; you will know when you have The Force,
not before that.
In the mean time, did you read my earlier reply, I was asking about the details
of the exception you are getting. That would bring us closer to a solution
for your problem.
|
|
|
|
|
hi,
the exception was :
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.
but when i put messageBox, he show message nurmously,
How i can add in listView?
Thank you verry mutch
|
|
|
|
|
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).
|
|
|
|
|
hello,
In 1st, i used a Timer, who get a packets every tick, but my application became heavy, for this reason i would use a Thread.
With Timer:
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {<br />
timer5->Interval=10;<br />
timer5->Start();<br />
}<br />
<br />
private: System::Void timer5_Tick(System::Object^ sender, System::EventArgs^ e) {<br />
<br />
While (there are packets which arrive ) {<br />
<br />
listView->Items->add (one paquets)<br />
<br />
}
Witht Thread { an exception on listView }
delegate void DelegateThreadTask();<br />
DelegateThreadTask ^ er;<br />
<br />
<br />
<br />
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {<br />
Threading::Thread(gcnew ThreadStart(this, &Form1::Traitement));<br />
t->Start();<br />
<br />
}<br />
.<br />
.<br />
.<br />
<br />
void Traitement( )<br />
{ while(true)<br />
{ThreadTask();<br />
Thread::Sleep(100); <br />
}<br />
<br />
}<br />
.<br />
.<br />
.<br />
void ThreadTask() <br />
{<br />
<br />
While (there are packets which arrive ) {<br />
<br />
listView->Items->add (one packets)<br />
<br />
}<br />
<br />
er = gcnew DelegateThreadTask(this, &Form1::ThreadTask);<br />
er->Invoke(); }<br />
<br />
<br />
<br />
Please hlep me,to get packets without heavy my système
Thank you verry mutch
|
|
|
|