ProWindow calling method during an event

215
1
09-17-2021 07:13 PM
JeanDesormeaux
New Contributor II

Hi,

I use the RowDeletedEvent to validate if it's permitted to erase a data or put it in history depending of user choice : 

RowDeletedEvent.Subscribe(OnRowDeleted, this.Table);

This is an async method and I try to set a property on my window before calling ShowDialog and nothing happing because of cross thread calling.

Example:

await QueuedTask.Run(() =>
{
    ProWindowClass pwc = new ProWindowClass();
    pwc.SetShowDateInput(Visibility.Visible);
    pwc.ShowDialog();
});

The dialog is not showing up. But if I put in comment SetShowDateInput, the dialog is showing up.

I tried to use a async method for SetShowDateInput and use his own Dispatcher and I always got this error: The calling thread cannot access this object because a different thread owns it.

What is the best practice to set control property of ProWindow during an event calling a await method?

Thank you,

Jean

Tags (2)
0 Kudos
1 Reply
JeanDesormeaux
New Contributor II

Ok I finally found how to call my Form, set parameters and call ShowDialog.

I needed to pass through FrameworkApplication.Current.Dispatcher.Invoke

 

Windows.DemandeSuppressionHistorique.ChoixEnum choix = Windows.DemandeSuppressionHistorique.ChoixEnum.Annuler;

FrameworkApplication.Current.Dispatcher.Invoke(() =>
{
    Windows.DemandeSuppressionHistorique wnd = new Windows.DemandeSuppressionHistorique();
    wnd.DemandeSupressionIsEnable(false);
    wnd.ShowDialog();

    choix = wnd.Choix;
});

 

Hope that could help someone eventually!

Jean

0 Kudos