Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / August 2006

Tip: Looking for answers? Try searching our database.

COM Connection points and C# delegates

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
lallous - 30 Aug 2006 07:39 GMT
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_OnItemProgress()  ....

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.Text = "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
Willy Denoyette [MVP] - 30 Aug 2006 13:47 GMT
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.BeginInvoke and Invoke.

Willy.

| Hello
|
[quoted text clipped - 51 lines]
| Regards,
| Elias

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.