How do I make the equivalent of TaskCompletionSource <nothing>?

I want to have an EventWaitHandle -like Task where I am waiting for it at one end and then just set it to complete the other end. TaskCompletionSource is what I want, but it requires passing in a value. I could just use a dummy value, but before I do that, I thought I'd see if there is a better solution.

The bottom line is to use Task.WaitAny .

+3


source share


1 answer


The most common scenario I've seen in source code is to simply create an empty struct

one that is not equivalent in any way. Or use bool

as a dummy:

internal struct Void { }

      

And then:



var tcs = new TaskCompletionSource<Void>();

      

I've seen this generic pattern in the BCL source code :

// Special internal struct that we use to signify that we are not interested in
// a Task<VoidTaskResult> result.
internal struct VoidTaskResult { }

      

+4


source







All Articles