I am using the IDms class to create + use Views.
I like to understand why the
- dms.GetView(viewId);
would return a Not found exception when used right after creating it with
- int viewId = dms.CreateView(new ViewConfiguration(newViewName, parentView));
When I add a sleep, the GetView does return the newly created view.
I rather not use a sleep and understand what we would be waiting on to ensure my logic will work regardless of cluster / system size.
Hi Mieke,
The dms.CreateView() method is actually asynchronous. It instructs DataMiner to create the view, but it does not wait until the view is fully available in the system, as you've already noticed. As a result, calling dms.GetView(viewId) immediately afterwards can still throw a "Not found" exception because the creation has not yet been fully processed and synchronized.
Instead of using a fixed Thread.Sleep(), it's better to implement a polling loop that checks whether the view exists every x 100 milliseconds. Make sure to also include a timeout and throw a TimeoutException when exceeded, to avoid ending up in an endless loop on slower or heavily loaded systems/clusters.
That way, your logic remains reliable regardless of cluster size or system load.