473,666 Members | 2,058 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

COM Connection points and C# delegates

Hello

I am not very experienced with this issue and would your opinion on
whether it is healthy or not:
1) I created an ATL COM object (say MyCOM):
- that supports connection points
- that exposes couple of methods such as:
BeginOperation( )
GetInformation( )
- Exposed some events in the _IMyCOMEvents interface which was created
automatically by the wizard, such as:
OnNewItem()
OnProgressItem( )
OnEndItem()
2) Implemented the connection points, etc...
Some information about BeginOperation( ):
1) It takes some initial parameters and stores them in the class member
variables
2) It creates a thread (CreateThread API), passing "this" as context
3) returns to the caller
The thread proc of BeginOperation( ):
1) do some lenghty operations (like file copying)
2) while doing the operations, fire the events when needed:
Fire_OnItemProg ress() ....
I wanted to test this COM from C#, so:
1)Added reference to the COM
2)created a new instance of the object in the form' s constructor
3)Added new delegates to the object's OnNew, OnEnd, ...
The delegates updates the screen such as:
void OnNewItem(int itemNo)
{
StatusLabel.Tex t = "Currently processing item #" + itemNo.ToString ();

}
etc...

Now, I am facing some weird issues:
1)sometimes, events are called, but only one line is being executed,
and then directly another event is being fired, w/o the first one
finishing
2)if application is ran w/ the debugger, it looks like the screen is
not updated as if some events are not triggered.
Please advise if this is the correct way of doing this.
Regards,
Elias
Aug 30 '06 #1
1 2112
Note that doing so, you will have to marshal the update of the UI to the UI
thread, your event handlers do run on an auxiliary thread (the one created
in your component), so you may not access the UI elements directly. Check
the docs on Control.BeginIn voke and Invoke.

Willy.

"lallous" <la*****@lgwm.o rgwrote in message
news:uS******** *****@TK2MSFTNG P06.phx.gbl...
| Hello
|
| I am not very experienced with this issue and would your opinion on
| whether it is healthy or not:
|
|
| 1) I created an ATL COM object (say MyCOM):
| - that supports connection points
| - that exposes couple of methods such as:
| BeginOperation( )
| GetInformation( )
| - Exposed some events in the _IMyCOMEvents interface which was created
| automatically by the wizard, such as:
| OnNewItem()
| OnProgressItem( )
| OnEndItem()
|
|
| 2) Implemented the connection points, etc...
|
|
| Some information about BeginOperation( ):
|
|
| 1) It takes some initial parameters and stores them in the class member
| variables
| 2) It creates a thread (CreateThread API), passing "this" as context
| 3) returns to the caller
|
|
| The thread proc of BeginOperation( ):
| 1) do some lenghty operations (like file copying)
| 2) while doing the operations, fire the events when needed:
| Fire_OnItemProg ress() ....
|
|
| I wanted to test this COM from C#, so:
|
|
| 1)Added reference to the COM
| 2)created a new instance of the object in the form' s constructor
| 3)Added new delegates to the object's OnNew, OnEnd, ...
| The delegates updates the screen such as:
| void OnNewItem(int itemNo)
| {
| StatusLabel.Tex t = "Currently processing item #" + itemNo.ToString ();
|
|
|
| }
|
|
| etc...
|
| Now, I am facing some weird issues:
| 1)sometimes, events are called, but only one line is being executed,
| and then directly another event is being fired, w/o the first one
| finishing
| 2)if application is ran w/ the debugger, it looks like the screen is
| not updated as if some events are not triggered.
|
|
| Please advise if this is the correct way of doing this.
|
|
| Regards,
| Elias
|
|
Aug 30 '06 #2

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

Similar topics

7
5132
by: Adam Clauss | last post by:
I am trying to work-around a firewall which limits me to only being able to accept inbound connections on port 80. Unfortunately, I need to two different applications to be able to accept connections. I know of no "standard" way to make this work (and, its quite possible that I am on the totally wrong track here and there just isn't a way to do this). I am trying to determine if it would be possible to write a 'gateway' program that...
4
22875
by: LP | last post by:
Hello! I am still transitioning from VB.NET to C#. I undertand the basic concepts of Delegates, more so of Events and somewhat understand AsyncCallback methods. But I need some clarification on when to use one over another? If anyone could provide any additional info, your comments, best practices, any good articles, specific examples, etc. Thank you
2
1637
by: Russell Hind | last post by:
I have a delegate which I use to store a current 'state' function (for a statemachine inside a form). __delegate void State_t(const Message_c& Message); I assign to it such as m_State = new State_t(this, StateShutdown); How can I later check which method the State is pointing to? And is
29
7041
by: Bryce K. Nielsen | last post by:
Suddenly this week, I've started getting this error message: System.Data.SqlClient.SqlConnection(GetOpenConnection)ExecuteNonQuery requires an open and available Connection. The connection's current state is connecting. I'm very puzzled since I'm not calling "ExecuteNonQuery" and I am calling "Open", which I've always assumed was Synchronous, i.e. would not return until either A) the connection was open or B) there was an error. Here...
4
1850
by: Francisco Domingues | last post by:
Hi all, Someone can help me in accomplish a connection to 2 wms services. I could connect once but I changed something on the code and now I can't get the things work, the connection fails. Here is the link to the viewer:
6
2653
by: =?Utf-8?B?T2xkQ2FEb2c=?= | last post by:
My question is regarding the use of delegates in C#. I see how .Net uses delegates to wire event handlers to events. It’s an object created by a single line of code by the system and that makes perfect sense to me. I understand that there is a lot of code underneath that the system has created that makes it all work, thereby making it pretty efficient for the programmer. Outside of the use of delegates to wire event handlers, you can...
7
3415
by: Siegfried Heintze | last post by:
I'm studying the book "Microsoft Visual Basic.NET Language Reference" and I would like some clarify the difference between events and delegates. On page 156 I see a WinForms example of timer that uses the "WithEvents" and events. There is another example on page 124 that shows how to use delegates to sort an array. I don't understand the difference between events and delegates. Are they redundant features? How do I decide which to use? ...
69
5563
by: raylopez99 | last post by:
They usually don't teach you in most textbooks I've seen that delegates can be used to call class methods from classes that are 'unaware' of the delegate, so long as the class has the same signature for the method (i.e., as below, int Square (int)). Here is an example to show that feature. Note class "UnAwareClass" has its methods Square and Cuber called by a class DelegateClass. This is because these methods in UnAwareClass have the...
3
1779
by: puzzlecracker | last post by:
What I currently have and request a suggestion to modularize it public sealed class Connection: BaseConnection{ //I have to process about 30 events public event Handler1=handler1; public event Handler2=handler2; public event Handler3=handler3; public event Handler4=handler4;
0
8356
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
8869
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...
1
8551
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8639
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
7386
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...
1
6198
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5664
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
4368
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1775
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.