473,395 Members | 1,692 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,395 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 2690
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.