I am having fun working with System.Threading.Tasks
. Many of the code samples I see, however, look something like so:
Dim lcTask = Task.Factory.StartNew(Sub() DoSomeWork())
Dim lcTaskLong = Task.Factory.StartNew(Sub() DoSomeWork(), TaskCreationOptions.LongRunning)
Task.WaitAll(lcTask, lcTaskLong)
That's the extent of the sample.
Tasks implement IDisposable
, so obviously I'm supposed to dispose of them, but what if I just want to "Fire and Forget"?
If I don't dispose, will I leak threads/handles/memory/karma? Am I using tasks "wrong"? (Should just use a delegate and leave tasks alone?)
Can I dispose in a ContinueWith()
? (That seems like playing Russian Roulette.)