THREADS FOR EVENTS???

Topics: CAB & Smart Client Software Factory
Jan 11, 2006 at 1:40 PM
originally posted by: ioniuy

Do I need to use diferent threads to pubish an event from a method that is being executed in response to a subcription to another event publication???

A better explanation:
I have a class A that publishes an event A1 .
I have another class B that has a subscription to A1.
B publishes an event B1
When A executes the publication A1, B runs the method that is inside the subcription to A1 and inside this method, B1 is publicated...
This is not working right now. is it a bug or do I need to use threads?

Thanks so much
Jan 11, 2006 at 2:12 PM
originally posted by: eugeniop

What are your current threading settings for each subscriber?
Jan 11, 2006 at 2:24 PM
originally posted by: ioniuy

I have not set any threading setting for the subscribers. I guess it has a default value.
Jan 12, 2006 at 8:23 AM
originally posted by: eugeniop

ok. Then the subscribers (all of them) run on the thread of the publisher. What is the error you see?

It might happen that your publisher (A) is running in a background thread itself and you are updating a UI component? (that needs to run on the UI thread)

Is there an exception thrown?
Jan 12, 2006 at 12:37 PM
originally posted by: ioniuy

Here is a brief of the code that we are using.


public class FieldInterpreter : IInterpreter
{
private RemoteHelp remoteHelp = null;

EventPublication(" topic://nDesktop/Operacion/pedirRemoteHelp")
public event EventHandler<DictionaryEventArgs> PedirRemoteHelp;

private Dictionary<Uri, Control> ListBoxInterpretEvent(FieldToDisplayEvent pEvento)
{
//Pedir remoteHelp
DictionaryEventArgs args = new DictionaryEventArgs();
//******Here We publish the first one that is subscribed in the OperacionController class (Look down in the text) - 1*******//
PedirRemoteHelp(this, args);
// When coming back remotehelp is null cause there was a subscription that did not worked//
if (remoteHelp == null) throw new Exception("No se devolvio la ayuda remota desde el servidor");
}

EventSubscription(" topic://nDesktop/Operacion/devolverRemoteHelp")
private void RecibirRemoteHelp(object sender, DictionaryEventArgs e)
{
// ******* 3 This is the subscription that is not working that is being publicated in the OperacionController class********//
remoteHelp = (RemoteHelp)e.Data"remoteHelp";
}
}

public class OperacionController : Controller
{
EventPublication("topic://nDesktop/Operacion/devolverRemoteHelp")
public event EventHandler<DictionaryEventArgs> DevolverRemoteHelpEvent;


EventSubscription("topic://nDesktop/Operacion/pedirRemoteHelp")
public void DevolverRemoteHelp(object sender, DictionaryEventArgs args)
{
DictionaryEventArgs e = new DictionaryEventArgs();
RemoteHelp remoteHelp = Servicio.CreateRemoteHelpSession();
e.Data.Add("remoteHelp", remoteHelp);
// ********** lHere we publish the second event for which the subscribed method in the upper class is not working. 2*********/////
DevolverRemoteHelpEvent(this, e);
}
}
Jan 12, 2006 at 3:35 PM
originally posted by: eugeniop

Most probably the Events are not being wired. Are these objects added to the workitem? How are they created?

You might want to use the Visualizer to see if CAB knows about these events.

Also check for "null" on the Events themselves. If they are null then it means that events are not being wired.
Jan 13, 2006 at 6:02 AM
originally posted by: BradWilsonMSFT

The subscription isn't working because the receiving method is marked "private". CAB does not do private reflection. Change the visibility of the method to "public" and it should work.