473,799 Members | 3,167 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Using com object in .NET

I have an activex control that is used in an old app originally written in
VB6. It works good. I updated the VB6 app to VB.net. Got it working, sort
of.

The activex control uses withevents and fires an event when there is
incoming message traffic. I need to capture that data. The event fires
sometimes. I know it should be firing more often because i run the vb6 app
and watch the traffic.

When I look at the debuger output I see a lot of this "A first chance
exception of type 'System.Invalid OperationExcept ion' occurred in
System.Windows. Forms.dll".

In addition it doesnt act like I intend. I can push a message out to the
console but if i try to update a form control it doesnt work.

I want to be able to use this activex control in C# without the withevents.

Also, The activex control is a an exe not a dll. I am suspecting a thread
problem here but not sure what to do next.

Thanks for any help!!
Brad
Jul 21 '06 #1
4 1587
Hi Brad,

Welcome to the MSDN newsgroup.

From your description, I understand you've upgraded a VB6 application to
VB.NET(.net framework 1.1 or 2.0?), this application use an activeX
control, and it is hosted through COM interop in the current VB.NET winform
application. The activeX control will raise some events and send
notifications, however, you found that in the event handler, if you try
updating the controls on the main form, you'll get
"System.Invalid OperationExcept ion" exception while it works well send info
into Console buffer, correct?

Based on my experience, this is likely a thread cooperate issue as you've
expected. Is the code that updateing the controls on form put in your
activeX control's event handler and have you checked that whether the event
handler code is executed in a separate thread from the windows
application's main UI thread? The potential cause is that the code which
updating the controls on the form is executed on a worker thread other than
the main UI thread, and for form controls(they'r e win32 controls which are
created on the main UI thread) which can only be manipulated under the UI
thread in which they're created. Therefore, we can not directly reference
and manipulate them in a separate thread, this restriction is enforced in
..net framework 2.0.

For the scenario we want to accessing and updating the controls on windows
form in a non-UI workerthread, we can use the following methods(on Control
instance) to marshal a function call into the main UI thread of that
control:

#Control.Invoke Method
http://msdn2.microsoft.com/en-us/lib...control.invoke
..aspx

#Control.BeginI nvoke Method
http://msdn2.microsoft.com/en-us/lib...control.begini
nvoke.aspx

e.g. Suppose we have the following function which will update the controls
on form:

private void UpdateControlsO nForm(object sender, EventArgs e) {
TextBox1.Text = ........;
............... ........
}

In a non-UI worker thread, we can use the below code to marshal the
function call onto the control's UI thread:

//myControl is a control on the form and created on the main UI thread

myControl.Invok e(new EventHandler(Up dateControlsOnF orm));
In addition, here are some good web articles and msdn reference describing
this problem:

#Updating Controls From Worker Threads
http://codemilitia.com/blogs/tobin.t.../04/10/12.aspx

#How to: Manipulate Controls from Threads
http://msdn2.microsoft.com/en-us/library/757y83z4.aspx

#WinForms UI Thread Invokes: An In-Depth Review of
Invoke/BeginInvoke/InvokeRequred
http://weblogs.asp.net/justin_rogers...es/126345.aspx

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

=============== =============== =============== =====

Get notification to my posts through email? Please refer to

http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial

response from the community or a Microsoft Support Engineer within 1
business day is

acceptable. Please note that each follow up response may take approximately
2 business days

as the support professional working with you may need further investigation
to reach the

most efficient resolution. The offering is not appropriate for situations
that require

urgent, real-time or phone-based interactions or complex project analysis
and dump analysis

issues. Issues of this nature are best handled working with a dedicated
Microsoft Support

Engineer by contacting Microsoft Customer Support Services (CSS) at

http://msdn.microsoft.com/subscripti...t/default.aspx.

=============== =============== =============== =====

This posting is provided "AS IS" with no warranties, and confers no rights.



Jul 24 '06 #2
That sounds like some good places to start. Thanks!!
"Steven Cheng[MSFT]" <st*****@online .microsoft.comw rote in message
news:cv******** ******@TK2MSFTN GXA01.phx.gbl.. .
Hi Brad,

Welcome to the MSDN newsgroup.

From your description, I understand you've upgraded a VB6 application to
VB.NET(.net framework 1.1 or 2.0?), this application use an activeX
control, and it is hosted through COM interop in the current VB.NET
winform
application. The activeX control will raise some events and send
notifications, however, you found that in the event handler, if you try
updating the controls on the main form, you'll get
"System.Invalid OperationExcept ion" exception while it works well send info
into Console buffer, correct?

Based on my experience, this is likely a thread cooperate issue as you've
expected. Is the code that updateing the controls on form put in your
activeX control's event handler and have you checked that whether the
event
handler code is executed in a separate thread from the windows
application's main UI thread? The potential cause is that the code which
updating the controls on the form is executed on a worker thread other
than
the main UI thread, and for form controls(they'r e win32 controls which are
created on the main UI thread) which can only be manipulated under the UI
thread in which they're created. Therefore, we can not directly reference
and manipulate them in a separate thread, this restriction is enforced in
net framework 2.0.

For the scenario we want to accessing and updating the controls on windows
form in a non-UI workerthread, we can use the following methods(on Control
instance) to marshal a function call into the main UI thread of that
control:

#Control.Invoke Method
http://msdn2.microsoft.com/en-us/lib...control.invoke
aspx

#Control.BeginI nvoke Method
http://msdn2.microsoft.com/en-us/lib...control.begini
nvoke.aspx

e.g. Suppose we have the following function which will update the controls
on form:

private void UpdateControlsO nForm(object sender, EventArgs e) {
TextBox1.Text = ........;
............... .......
}

In a non-UI worker thread, we can use the below code to marshal the
function call onto the control's UI thread:

//myControl is a control on the form and created on the main UI thread

myControl.Invok e(new EventHandler(Up dateControlsOnF orm));
In addition, here are some good web articles and msdn reference describing
this problem:

#Updating Controls From Worker Threads
http://codemilitia.com/blogs/tobin.t.../04/10/12.aspx

#How to: Manipulate Controls from Threads
http://msdn2.microsoft.com/en-us/library/757y83z4.aspx

#WinForms UI Thread Invokes: An In-Depth Review of
Invoke/BeginInvoke/InvokeRequred
http://weblogs.asp.net/justin_rogers...es/126345.aspx

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

=============== =============== =============== =====

Get notification to my posts through email? Please refer to

http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial

response from the community or a Microsoft Support Engineer within 1
business day is

acceptable. Please note that each follow up response may take
approximately
2 business days

as the support professional working with you may need further
investigation
to reach the

most efficient resolution. The offering is not appropriate for situations
that require

urgent, real-time or phone-based interactions or complex project analysis
and dump analysis

issues. Issues of this nature are best handled working with a dedicated
Microsoft Support

Engineer by contacting Microsoft Customer Support Services (CSS) at

http://msdn.microsoft.com/subscripti...t/default.aspx.

=============== =============== =============== =====

This posting is provided "AS IS" with no warranties, and confers no
rights.



Jul 24 '06 #3
Thanks for your response Brad,

Glad that the information is of assistance. Please feel free to let me know
if you've got any progress or need any further help on this.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.

Jul 25 '06 #4
Thanks for your response Brad,

Glad that the information is of assistance. Please feel free to let me know
if you've got any progress or need any further help on this.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.

Jul 25 '06 #5

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

Similar topics

4
2072
by: Michael Sparks | last post by:
Anyway... At Europython Guido discussed with everyone the outstanding issue with decorators and there was a clear majority in favour of having them, which was good. From where I was sitting it looked like about 20:20 split on the following syntaxes: 1 def func(arg1, arg2, arg3) : function... 2 def func(arg1, arg2, arg3): function...
0
6706
by: Nashat Wanly | last post by:
HOW TO: Call a Parameterized Stored Procedure by Using ADO.NET and Visual C# .NET View products that this article applies to. This article was previously published under Q310070 For a Microsoft Visual Basic .NET version of this article, see 308049. For a Microsoft Visual C++ .NET version of this article, see 310071. For a Microsoft Visual J# .NET version of this article, see 320627. This article refers to the following Microsoft .NET...
28
20348
by: Daniel | last post by:
Hello =) I have an object which contains a method that should execute every x ms. I can use setInterval inside the object construct like this - self.setInterval('ObjectName.methodName()', this.pinginterval); - but is there no way to do this without using the literal ObjectName? If I write 'this.methodName()' I get "Line 1 Char 1: Object doesn't support this property or method." in IE, and nothing happens in Firebird.
11
2206
by: Doug | last post by:
Is there any harm in passing an object into a method with the 'ref' keyword if the object is already a reference variable? If not, is there any benefit?
17
4231
by: Danny J. Lesandrini | last post by:
The following code works with a standard MDB to navigate to a particluar record (with a DAO recordset, of course) but it's giving me problems in an ADP I'm working on. Dim rs As ADODB.Recordset Set rs = Me.RecordsetClone rs.Find "=" & lngContractID If Not rs.EOF Then Me.Bookmark = rs.Bookmark I must site the Heisenberb Uncertainty Principal here, as it
9
10906
by: Ben Dewey | last post by:
Project: ---------------------------- I am creating a HTTPS File Transfer App using ASP.NET and C#. I am utilizing ActiveDirectory and windows security to manage the permissions. Why reinvent the wheel, right? Everything so far is working well with the Active Directory. The problem I am having is with adding File Permissions to a directory. I am currently using some code courtesy of "Willy Denoyette "
4
3404
by: Chris | last post by:
Hi, everything works apart from the last line :-(( rng.Value2.ToString() An exception is thrown : "Old format or invalid type library" It gets compiled though (so he recognizes the property 'Value2'). So I suppose I'm using a incompatible type lib. I'm using Excel 2002 : Excel 10.0 Object Library
0
6439
by: Michelle Keys | last post by:
I am trying to call a print function to print a string from a database using javascript. Which is RC_DATA of Varchar2(2500). This is a javascript is not being used. I have a thing that needs to be modified: if(e.CommandName =="Print") { string parsedreceipt = null; parsedreceipt = DecodeReceipt (e.Item.Cells.Text); Session = parsedreceipt;
14
3169
by: MuZZy | last post by:
Hi, Lately i've been (and still am) fixing some memory leaks problems in the project i just took over when i got this new job. Among the other issues i've noticed that for localy created objects it makes difference to explicitly put them to null after working with them is done - it somehow makes the GC collect them sooner, like here: void SomeFunc() { MyClass c = new MyClass();
2
3502
by: Ryan | last post by:
Hi, I receive an access denied error (see below) when attempting to send an email with BodyFormat=MailFormat.Html from an asp.net page. Exactly the same code works fine in a console application, and also succeeds from the asp.net page with BodyFormat=MailFormat.Text. I've recently upgraded from W2K SP4 to WinXP SP2 and am using .Net Framework v1.1 SP1. The code worked fine under W2K SP4.
0
9685
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9538
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10473
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10249
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10025
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9068
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6804
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5461
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4138
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.