AnsweredAssumed Answered

LayerFactory causes QueuedTask.Run(...).Wait() to hang

Question asked by kirkktx on Mar 8, 2017
Latest reply on Mar 16, 2017 by wkaiser-esristaff

The Wait() method on the Task returned by QueuedTask.Run hangs when I try to use LayerFactory.

If I use await, it works as expected.  Am I doing something wrong?

 

This works:

protected override async void OnClick()
{
    await QueuedTask.Run(()=> {
            LayerFactory.CreateGroupLayer(MapView.Active.Map, 0, "group layer");
            Debug.Print("layer created");
        });
    Debug.Print("done");
}

But this hangs:

protected override void OnClick()
{
    QueuedTask.Run(()=> {
            LayerFactory.CreateGroupLayer(MapView.Active.Map, 0, "group layer");
            Debug.Print("layer created");
        }).Wait();
    Debug.Print("done");
}

This works (suggesting LayerFactory is clogging the plumbing):

protected override void OnClick()
{
    QueuedTask.Run(() => {
        for (int i = 0; i < 5; i++)
        {
            Debug.Print("Sleeping " + i);
            System.Threading.Thread.Sleep(1000);
        }
        Debug.Print("waking");
    }).Wait();
    Debug.Print("done");
}

Outcomes