I want to send some data from BackgroundPlugin to TabPlugin when TabPlugin is initialized-shown (tabPlugin is kind of camera).
I was able to do that with sending messages via RegisterCommunicationFilter and TransmitMessage but I have to wait for registration first in TabPlugin and then Transmit so when BackgroundPlugin responds TabPlugin has registered receiver. That part also works by using Task.
Now, the only problem with this setup is that if I switch tabs fast (between 1 to 2 seconds) then I get error message in event srv log “CommunicationService Same messageId being registered multiple times” and it seems that UnregisterReceiver in close() method of TabUserControl doesn’t finishes but then Init() comes with, again, registration…
I was thinking of using EnvinromentManager.Instance.SendMessage but I am not receiving anything using code
//This is from TabUserControl
message = new Message(PluginDefinition.TabUserControlLoaded);
EnvironmentManager.Instance.SendMessage(message, null, null);
//This is in BackgroundPlugin
EnvironmentManager.Instance.RegisterReceiver(TabUserControlLoadedHandler, new MessageIdFilter(PluginDefinition.TabUserControlLoaded));
Also, I should be able to return some data(object) to the sender using SendMessage?
We tried to reproduce but failed. Our modification sample worked fine. Let me introduce our modified code to you.
“BackgroundPlugin“
public override void Init()
{
EnvironmentManager.Instance.RegisterReceiver(TabUserControlLoadedHandler,
new MessageIdFilter(MIPPluginTabAndBackgroundDefinition.TabUserControlLoaded));
}
/// <summary>
/// Define in what Environments the current background task should be started.
/// </summary>
public override List<EnvironmentType> TargetEnvironments
{
get { return new List<EnvironmentType>() { EnvironmentType.Administration }; }
}
private object TabUserControlLoadedHandler(Message message, FQID destination, FQID sender)
{
System.Windows.Forms.MessageBox.Show("test", message.Data as string);
return null;
}
”VideoOS.Platform.Admin.TabUserControl”
private void button1_Click(object sender, EventArgs e)
{
message = new Message(MIPPluginTabAndBackgroundDefinition.TabUserControlLoaded);
message.Data = "header text";
EnvironmentManager.Instance.SendMessage(message, null, null);
}
Can you please test with these?
One more thing that I would like to explain is that this is inter-process communication when you use the EnvironmentManager, which means your background plugin must be a Management Client background plugin (as TargetEnvironments in my code indicate).
If what you want instead is cross-process communication, for instance communication from Event Server to Management Client or vice versa, you should use MessageCommunicationManager instead of EnvironmentManager. Please explore the Chat sample if you want to see this in.
The logic I had is same as yours, except my Environment is Service instead. So, it should work if I add EnvironmentType.Administration in the list of TargetEnvironments?
Currently, I am using MessageCommunicationManager and ok, it works but it takes some time to register and unregister and there is always possibility of error if NewTab is constructed but close() didn’t finished with unregistering…
That depends. TargetEnvironments governs where the BackgroundPlugin is loaded and running, and this has a larger impact on how your solution works..
If you want your BackgroundPlugin to be running in the Management Client and receive messages from within that Management Client instance (inter-process), then it is efficient.
If you want your BackgroundPlugin to be running in the Event Server and receive messages globally from all clients using your plugin (cross-process, could also be Smart Clients in addition to the Management Clients) there is no way around using MessageCommunication with the added complexity, resource pressure and communications timing.
I hope this adds some explanation and you now can do an informed choice between the two.