473,324 Members | 2,417 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

thread problem

Eps
ok i have a timer object in my windows forms application, the app also
makes use of a COM object which also uses threading.

I have a seperate class that deals with COM object but this class has to
pass infomation back to the main windows form from time to time, so i
pass the main form to the class that that calls the COM object so i can
access the windows form GUI.

However this always causes errors...

A first chance exception of type
'System.Reflection.TargetInvocationException' occurred in mscorlib.dll

A first chance exception of type 'System.InvalidOperationException'
occurred in System.Windows.Forms.dll

in the debugging window and the GUI never updates properly. I am fairly
certain it is to do with me calling the main form from the class that
deals with the COM object, probably a threading issue i think.

Anyone know how i can update my GUI from the seperate class ?

any help appreciated.

--
Eps
Nov 17 '05 #1
4 2688
yes you are correct it is a threading issue, remember that winform controls
are STA (single thread apartment) model and therefore you have to marshall
calls back to the UI thread to make an update to the UI. Check out the
following links, you have to check a property on the control called
'InvokeRequired' and then use 'BeginInvoke' with a delegate to get the
update done on the UI thread.

http://www.theserverside.net/discuss...hread_id=25063

http://msdn.microsoft.com/library/de...nvokeTopic.asp
HTH

Ollie Riches

"Eps" <ep*@mailinator.com> wrote in message
news:uO**************@TK2MSFTNGP12.phx.gbl...
ok i have a timer object in my windows forms application, the app also
makes use of a COM object which also uses threading.

I have a seperate class that deals with COM object but this class has to
pass infomation back to the main windows form from time to time, so i pass
the main form to the class that that calls the COM object so i can access
the windows form GUI.

However this always causes errors...

A first chance exception of type
'System.Reflection.TargetInvocationException' occurred in mscorlib.dll

A first chance exception of type 'System.InvalidOperationException'
occurred in System.Windows.Forms.dll

in the debugging window and the GUI never updates properly. I am fairly
certain it is to do with me calling the main form from the class that
deals with the COM object, probably a threading issue i think.

Anyone know how i can update my GUI from the seperate class ?

any help appreciated.

--
Eps

Nov 17 '05 #2
Eps <ep*@mailinator.com> wrote:
ok i have a timer object in my windows forms application, the app also
makes use of a COM object which also uses threading.

I have a seperate class that deals with COM object but this class has to
pass infomation back to the main windows form from time to time, so i
pass the main form to the class that that calls the COM object so i can
access the windows form GUI.

However this always causes errors...

A first chance exception of type
'System.Reflection.TargetInvocationException' occurred in mscorlib.dll

A first chance exception of type 'System.InvalidOperationException'
occurred in System.Windows.Forms.dll

in the debugging window and the GUI never updates properly. I am fairly
certain it is to do with me calling the main form from the class that
deals with the COM object, probably a threading issue i think.

Anyone know how i can update my GUI from the seperate class ?


See http://www.pobox.com/~skeet/csharp/t...winforms.shtml for
threading in Windows Forms - but quite how it should all work with COM,
I'm afraid I don't know. I've always tried to avoid COM as much as
possible :)

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 17 '05 #3
that would be 'yoda' as in small, green and talking in tongues then Jon.....

Ollie

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Eps <ep*@mailinator.com> wrote:
ok i have a timer object in my windows forms application, the app also
makes use of a COM object which also uses threading.

I have a seperate class that deals with COM object but this class has to
pass infomation back to the main windows form from time to time, so i
pass the main form to the class that that calls the COM object so i can
access the windows form GUI.

However this always causes errors...

A first chance exception of type
'System.Reflection.TargetInvocationException' occurred in mscorlib.dll

A first chance exception of type 'System.InvalidOperationException'
occurred in System.Windows.Forms.dll

in the debugging window and the GUI never updates properly. I am fairly
certain it is to do with me calling the main form from the class that
deals with the COM object, probably a threading issue i think.

Anyone know how i can update my GUI from the seperate class ?


See http://www.pobox.com/~skeet/csharp/t...winforms.shtml for
threading in Windows Forms - but quite how it should all work with COM,
I'm afraid I don't know. I've always tried to avoid COM as much as
possible :)

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 17 '05 #4
Ollie Riches <ol**********@phoneanalyser.net> wrote:
that would be 'yoda' as in small, green and talking in tongues then Jon.....


It would be "yoda" as in the name I used for the computer I built out
of bits and pieces while I was at university. It's the only computer
I've ever seen which not only *contained* a chopstick, but actually
*needed* it (in order to keep the ribbon connectors away from the
memory).

See http://www.pobox.com/~skeet/pics/yoda2.jpg for a piccie.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Tony Proctor | last post by:
Hi everyone We're experiencing some serious anomalies with the scheduling of ASP threads. I'd be interested to hear if anyone knows what algorithm is used (e.g. simple round-robin, or something...
7
by: Ivan | last post by:
Hi I have following problem: I'm creating two threads who are performing some tasks. When one thread finished I would like to restart her again (e.g. new job). Following example demonstrates...
20
by: Doug Thews | last post by:
I ran into an interesting re-pain delay after calling the Abort() method on a thread, but it only happens the very first time I call it. Every time afterward, there is no delay. I've got a...
6
by: Tomaz Koritnik | last post by:
I have a class that runs one of it's method in another thread. I use Thread object to do this and inside ThreadMethod I have an infinite loop: While (true) { // do something Thread.Sleep(100);...
13
by: Bob Day | last post by:
Using vs2003, vb.net I start a thread, giving it a name before start. Code snippet: 'give each thread a unique name (for later identification) Trunk_Thread.Name = "Trunk_0_Thread" ' allow...
4
by: fred | last post by:
I use a Synclock in a secondary thread and also stop the thread using the abort method. If the abort occurs while the thread is in the Synclock will the SyncLock always be released before the...
51
by: Hans | last post by:
Hi all, Is there a way that the program that created and started a thread also stops it. (My usage is a time-out). E.g. thread = threading.Thread(target=Loop.testLoop) thread.start() ...
14
by: joey.powell | last post by:
I am using VS2005 for a windows forms application. I need to be able to use a worker thread function to offload some processing from the UI thread. The worker thread will need access to a...
7
by: Sin Jeong-hun | last post by:
Hi. I'm writing a Client/Multi-threaded Server program on Windows Vista. It worked fine on Windows Vista, but when the server ran on Windows XP, I/O operation has been aborted because of either...
34
by: Creativ | last post by:
Why does Thread class not support IDisposable? It's creating quite some problem. Namely, it can exhaust the resource and you have not control over it.
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.