You should always post the error message in your question so we can see what the exact issue is.
At a guess, you are seeing a cross thread exception. This happens when you try to do UI actions from a thread other than the UI Thread. You can check this by setting a breakpoint before doing any UI work, then look at the Thread window to see what thread you are on.
If you are not on the UI thread, then you need to marshal to the UI thread before doing the UI work.
I work with both WPF and WinForms, both do the marshalling differently. So I have a common helper implementation that I use. Here is the helper class:
public static class DispatcherHelper
{
public static void Execute(Action action)
{
if (Application.OpenForms.Count == 0)
{
action.Invoke();
return;
}
try
{
if (Application.OpenForms[0]!.InvokeRequired)
Application.OpenForms[0]?.Invoke(action);
else
action.Invoke();
}
catch (Exception)
{
}
}
}
Then to use:
DispatcherHelper.Execute(() =>
{
});
So, in your case, I think you would use it like this:
if (positions == null || positions.Count == 0)
{
DispatcherHelper.Execute(() =>
this.Alert("No data to display.", FAlert.enmType.Warning));
}