I have a WPF application that makes use of a resource. This resource can be used in two ways:
- IU events. When the user clicks on different elements of the view, it writes a value.
- On a background task. Periodically, readings of various values are made.
I have problems when a reading is in progress and the user has to do a writing. I want to stack the calls to the resource methods in order to execute them sequentially.
These are resource's methods:
async Task <bit []> ReadBitsAsync (byte id)
async Task <ushort []> ReadUshortsAsync (byte id)
async Task WriteBitAsync (byte id, ushort position, bool value)
async Task WriteUshortAsync (byte id, ushort position, ushort value)
I've tried doing it with the lock
statement, but you can't await
a task
inside a lock
statement.
Is there any way to stack these method calls with all parameter values?