473,732 Members | 2,214 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ISynchronizeInv oke.BeginInvoke and polymorphic parameters

I have a problem when using ISynchronizeInv oke.BeginInvoke with polymorphic
parameters. It seems that if I try to call BeginInvoke and in the array of
parameters place an object that's derived from a base class my method
expects as a parameter, the method gets only an object of the type of the
base class, rather than my full object.

I know this sounds convoluted, so here's an example. My program consists of
an engine and a WindowsForms UI. The engine operates on a separate thread
and reports back to the UI using the main form's ISynchronizeInv oke
interface. When engine performs some operation during which it throws an
exception it calls OnProcessingSta geException which in turn fires and event
that will be received by the UI. Here's how it looks.

public event EventHandler ProcessingStage Exception;

void FireEvent(Event Handler handler, Object sender, EventArgs e) {
if (this.target != null && handler != null) {
this.target.Beg inInvoke(handle r, new object[] {sender, e});
}
}

private void OnProcessingSta geException(obj ect sender, EventArgs e) {
FireEvent(Proce ssingStageExcep tion, this, (ExceptionEvent Args)e);
}

The main form's method for handling this event is defined as follows:

private void OnProcessingSta geException(obj ect sender, EventArgs e) {
MessageBox.Show (
this, string.Format(" Error performing operation.\nDet ails: {0}",
((ExceptionEven tArgs)e).ex), "VideoInspector ");
}

The problem is that when I try to cast ((ExceptionEven tArgs)e) I get
InvalidCast exception, even though ExceptionEventA rgs inherits from
EventArgs.

Is this by desing or did I hit some kind of a bug?

Thanks for your help

Andrew
Nov 15 '05 #1
0 1420

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

Similar topics

2
2689
by: Sandor Heese | last post by:
Question, When using BeginInvoke (on a From to marshal to the UI thread) with the EventHandler delegate I see some strange behaviour. The problem is that I call the UpdateTextBox method with a class derived from EventArgs ( i.e. MyEventArgs) and when the BeginInvoke is called and the UpdateTextBox methode is call on the UI thread the parameter e (EventArgs) does not contain the derived MyEventArgs object but a EventArgs object. The...
9
2256
by: GM | last post by:
Hi, My application has a need to cache a number of shared reference lists containing basic business objects. In order to improve performance these lists are fetched and updated in the background. When a UI is required to display one of these reference lists it requests it by name from the cache. If the list already exists in the cache it is returned to the caller otherwise a brand new empty one is created and returned. This new empty...
20
2222
by: verec | last post by:
One problem I've come accross in designing a specific version of auto_ptr is that I have to disntiguish between "polymorphic" arguments and "plain" ones, because the template has to, internally, cast to void *. Specifically, template <typename T> void f(T * t) { void * p = dynamic_cast<void *>(t) ; } will not compile if T isn't of a class that has somewhere at least
4
2369
by: Jon | last post by:
Why are out parmeters included in an BeginInvoke? They seem to do nothing? TestProgam: using System; namespace TempConsole { class App { public delegate void MyDelegate( out byte b, out string s );
0
2498
by: Wavemaker | last post by:
One of the things I've struggled with from time to time is handling events raised on different threads. For example, an object could be listening to events from one or more objects running in different threads besides itself. There is a concern for thread safety. There are various ways of dealing with this. One way is to make the class thread safe by putting in locks. But another way is to stream the events from the various threads into a...
1
3086
by: Thai Mai Shu | last post by:
What is wrong with my call below. If I change the delegate and the CallBackComplete function to not take in parameters then the .Invoke call works fine. As soon as I put the parameters back I get "Parameter count mismatch." error. Am I supposed to implement ISynchronizeInvoke in order to call .Invoke? If so, why does it work when the method i am trying to invoke has no parameters. Private Delegate Sub CallbackCompleteDelegate(ByVal...
4
4027
by: jherl | last post by:
I am getting an "Object reference not set to an instance of an object" when I try to execute the Invoke method. I have it set up as follows: --- Private _syncObject As System.ComponentModel.ISynchronizeInvoke .. .. .. Dim args(0) As Object Dim d As New RaiseReceiveEvent(AddressOf OnReceive) ..
1
1043
by: dusanv | last post by:
Hi, I'm trying to call 'BeginInvoke' on a member function of the Form Class (Close function). What delegate do I use for that? Thanks.
8
1648
by: Angelwings | last post by:
Hi everyone, I've to write my own definition of a BST with polymorphic data, as an university course project. I have troubles about comparing data when it's defined as polymorphic pointer. In my situation I've something like: class A {} class B : public A {} class C : public A {}
0
8946
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
9447
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
9307
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
9181
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
8186
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
6735
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
6031
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();...
2
2721
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2180
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.