Note that there are some explanatory texts on larger screens.

plurals
  1. POEvent Subscription Lost when Passing Instance Object
    primarykey
    data
    text
    <p>I have created an external class (<code>TheClass</code>) with an event (<code>TheEvent</code>) and subscribe to it from within another class's Panel constructor:</p> <pre><code>public aPanel() { ... theClassInstance.TheEvent += new WaitCallback(aMethod); ... } </code></pre> <p>Later in the program, I call a method passing <code>theClassInstance</code> as the only parameter</p> <pre><code>bMethod((object)theClassInstance); </code></pre> <p>where</p> <pre><code>public void bMethod(object inputTheClassInstance) { ... } </code></pre> <p>Knowing that the input object is of type <code>TheClass</code>, I do the following:</p> <pre><code>public void bMethod(object inputTheClassInstace) { TheClass theClassInput = (TheClass)inputTheClassInstace; ... } </code></pre> <p>Later in <code>bMethod()</code> I call a method <code>RaiseEvent()</code> exposed by <code>theClassInput</code> which will actually trigger the event. In <code>RaiseEvent()</code> I have</p> <pre><code>if(this.TheEvent != null) TheEvent(); </code></pre> <p>to make sure something is subscribed to the event but <code>this.TheEvent</code> equates to null. If I place the subscription within <code>bMethod()</code></p> <pre><code>bMethod(...) { ... theClassInput.TheEvent += new WaitCallback(aMethod); ... } </code></pre> <p>it works just fine but I would like to keep it in the Panel's constructor. I figured that because <code>theClassInput</code> is pointing to the same object as <code>theClassInstance</code> it wouldn't make a difference which triggers the event. Any thoughts on how I can keep the subscription in the constructor while calling it from within <code>bMethod()</code> using <code>theClassInput</code>?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload