I'm having issues with a thread disappearing. I'm ...
# dotnet
t
I'm having issues with a thread disappearing. I'm sure this is an async/await problem, but I can't figure out what I'm supposed to do in the context of Pulumi. Here's a sample:
Copy code
private static void FunctionDoesNotFinish(Output<string> someValue)
{
    _ = someValue.Apply<string?>(async c =>
    {
        Console.WriteLine("Start");

        for (int i = 0; i <= 1000; i++)
        {
            Console.WriteLine(i);
            await Task.Delay(1);
        }

        Console.WriteLine("End");

        return null;
    });
}
And here is the output:
Diagnostics:
pulumipulumiStack (AzureSqlAad-dev-asa2):
Start
0
1
2
3
Numbers 4-100 never appear. I'm guessing
Output.Create
might be recommended, but I can't get that to work either.
Copy code
private static void FunctionDoesNotFinish(Output<string> someValue)
{
    _ = someValue.Apply<string?>(s => Output.Create<string?>(SomeMethod()));
}

private static async Task<string?> SomeMethod()
{
    Console.WriteLine("Start");

    for (int i = 0; i <= 1000; i++)
    {
        Console.WriteLine(i);
        await Task.Delay(1);
    }

    Console.WriteLine("End");

    return null;
}
NOTE: My actual code is just adding a user to the DB, so I don't actually care about the return value. @tall-librarian-49374
t
It’s likely because you ignore the return value from
Apply
. We expect you to “register” all outputs somewhere in resource model so that we know we need to await it.
Search for
RegisterOutputs
in our .NET SDK source code to get a sense of what’s going on there.
If you are in Stack, you should assign it to an output property. If you are in a Component, you can register those explicitly.
t
That worked. Thanks.