I tested the code on my Admin plugin (basically, this is what you had written on the post), and it works fine. Please see below, we used the following code. Our VMS is 2022 R2 XPCO.
private void button1_Click(object sender, EventArgs e)
{
var ms = new ManagementServer(EnvironmentManager.Instance.MasterSite.ServerId);
ms.UserDefinedEventFolder.AddUserDefinedEvent(textBoxName.Text);
Configuration.Instance.RefreshConfiguration(Kind.TriggerEvent);
var itemGet = Configuration.Instance.GetItemsByKind(Kind.TriggerEvent, ItemHierarchy.SystemDefined);
}
If add another GetItemsByKind( ) before adding user-defined event, the test will fail.
It seems that Configuration instance cached the items and RefreshConfiguration( ) does not work.
private void button1_Click(object sender, EventArgs e)
{
var itemFirstGet = Configuration.Instance.GetItemsByKind(Kind.TriggerEvent, ItemHierarchy.SystemDefined);
var ms = new ManagementServer(EnvironmentManager.Instance.MasterSite.ServerId);
ms.UserDefinedEventFolder.AddUserDefinedEvent(textBoxName.Text);
Configuration.Instance.RefreshConfiguration(Kind.TriggerEvent);
var itemGet = Configuration.Instance.GetItemsByKind(Kind.TriggerEvent, ItemHierarchy.SystemDefined);
}
We got a news from Milestone Development. Unfortunately, what you want to do is not possible through APIs. Please see below explanation from Milestone Development.
-----
RefreshConfiguration only works for plugin configurations, so basically Items defined by plugins.
Any build-in item configuration is maintained by the environment (Management Client in this cache) and thus cannot be refreshed through MIP. We will update the documentation to state this for next release.