Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wait for ActivateItem close? #607

Closed
michasacuer opened this issue May 26, 2019 · 3 comments
Closed

Wait for ActivateItem close? #607

michasacuer opened this issue May 26, 2019 · 3 comments

Comments

@michasacuer
Copy link

michasacuer commented May 26, 2019

I have a question. I have button where i launch ActivateItem:

    public void LoadTaskManagerPage()
    {
        this.ActivateItem(new TaskManagerViewModel(this.LoggedUser, this.repository));

        if (this.LoggedUser.GetUserTask() != null)
        {
            this.IsActiveTaskButtonVisible = Visibility.Visible;
            this.NotifyOfPropertyChange(() => this.IsActiveTaskButtonVisible);
        }
    }

Is it possible to hang an app and go to if statement only, if ActivateItem ends?

How to wait for end of ActivateItem in Caliburn.Micro?

I tried something like:

    public void LoadTaskManagerPage()
    {
        var taskManagerTask = Task.Run(() => this.ActivateItem(new TaskManagerViewModel(this.LoggedUser, this.repository)));
        taskManagerTask.Wait();

        if (!this.LoggedUser.GetUserTask().IsTaskTakenByUser())
        {
            this.IsActiveTaskButtonVisible = Visibility.Visible;
            this.NotifyOfPropertyChange(() => this.IsActiveTaskButtonVisible);
        }
    }

With Tasks, but when i click on LoadTaskManagerPage() it wont show any window, application hangs forever

@nigel-sampson
Copy link
Contributor

You will "soon" with the 4.0.0 builds which make ActivateItem into ActivateItemAsync that you can await.

It's still in development, but the in progress packages are available from MyGet (link in the readme.md).

@michasacuer
Copy link
Author

michasacuer commented May 27, 2019

@nigel-sampson Thansk for your advice. But after changing my code to:

public void LoadTaskManagerPage()
{
    this.ActivateItemAsync(new TaskManagerViewModel(this.LoggedUser, this.repository));

    if (this.LoggedUser.GetUserTask() != null)
    {
        this.IsActiveTaskButtonVisible = Visibility.Visible;
        this.NotifyOfPropertyChange(() => this.IsActiveTaskButtonVisible);
    }
}

Its still hitting if before ActivateItem close (im using TryCloseAsync() for closing Screen. Have you any advice, how to achive what i want to? (activate if statement only, if activeItem close. Thanks for suggestions

@nigel-sampson
Copy link
Contributor

ActivateItemAsync is asynchronous which means it needs to be awaited. I'd suggest reading up on The Task asynchronous programming model in C#.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants