4 observations:
1) Don't use Task for this purpose. They add overhead and consume unneeded resources. Moreover, they are inherently "lazy", meaning you don't know exactly how much time passes between task invocation and task run.
2) In order to detect a multi-click (double, triple, etc..) you only need to know how much time has passed from the previous click.
3) Don't use DateTime to measure small times. Use Stopwatch or system ticks.
I'd use a parallel thread or an UI timer to monitor a couple of variables, where I'd store the timestamp of the last click and how many clicks have been performed within a maximum time frame from the first one.
The following is a quick-and-dirty example of the concept:
You have to address concurrency, instantiate/start the timer, and adapt it to your needs. You probably need to replicate the logic (partial code) of OnToolMouseUp to OnToolMouseDown.
You might also want to test for a maximum time in-between ticks (not only between the first and the last) and parametrize everything.
int ClickCountSoFar;
long LastClickTime;
long MaxTimeToMultiClick = Stopwatch.Frequency / 100;
void RaiseClickEvent(int clickCount)
{
if (clickCount == 1)
RaiseSingleClick();
else if (clickCount == 2)
RaiseDoubleClick();
else if (clickCount == 3)
RaiseTripleClick();
}
void OnToolMouseUp(..)
{
var now = Stopwatch.GetTimestamp();
if (now - LastClickTime <= MaxTimeToMultiClick)
ClickCountSoFar++;
else
ClickCountSoFar = 1;
LastClickTime = now;
}
void OnTimer(..)
{
var now = Stopwatch.GetTimestamp();
if (ClickCountSoFar > 0 && now - LastClickTime > MaxTimeToMultiClick)
{
RaiseClickEvent(ClickCountSoFar);
ClickCountSoFar = 0;
LastClickTime = 0;
}
}