TK Tang
TK Tang

Reputation: 113

C# retrieving an object associated with thread

I'm new to C# and only have a rudimentary understanding of threading so sorry if I'm asking the question based on incorrect assumptions.

I have a method that looks this:

public async Task<ServiceResult> AttemptConnectionAsync()
        {
            return new ServiceResult(true);
        }

I am calling this method from a different class:

Task<ServiceResult> sr = someObjectInstance.AttemptConnectionAsync();

How do I get the ServiceResult, the object itself "attached" to the thread and access its attributes instead of the thread? Like this:

Assert.IsNull(ServiceResult.Errors);

Upvotes: 1

Views: 48

Answers (1)

CodeNotFound
CodeNotFound

Reputation: 23190

Just use the await keyword like this:

ServiceResult sr = await someObjectInstance.AttemptConnectionAsync();

To learn more about Asynchronous Programming you can check this link.

Upvotes: 2

Related Questions