VB.NET-同时发生多个异步“超时”类型的操作

VB.NET-同时发生多个异步“超时”类型的操作,vb.net,multithreading,asynchronous,Vb.net,Multithreading,Asynchronous,我在VB.NET的多线程编程中遇到了一些问题,我不明白为什么。在我正在编写的一个程序中,我希望在面板对象上以设定的时间间隔xInterval毫秒定期出现黄色椭圆点,然后在显示时间毫秒后再次用黑色椭圆覆盖消失。我的密码是: Sub sparkles() ... 'pointArray() contains the points where the dots are to appear For i as Integer = 0 to pointArray.Length -

我在VB.NET的多线程编程中遇到了一些问题,我不明白为什么。在我正在编写的一个程序中,我希望在面板对象上以设定的时间间隔xInterval毫秒定期出现黄色椭圆点,然后在显示时间毫秒后再次用黑色椭圆覆盖消失。我的密码是:

Sub sparkles()
    ...
    'pointArray() contains the points where the dots are to appear

    For i as Integer = 0 to pointArray.Length - 1
        flashPoint(pointArray(i))
        Threading.Thread.Sleep(xInterval)
    Next i
End Sub

Async Sub flashPoint(point As Point) As Task
    *CODE TO DRAW YELLOW ELLIPSE AT point*    
    Await killPoint(point)
End Sub

Function killPoint(point As Point) As Task
    Threading.Thread.Sleep(xFlashtime)
    *CODE TO DRAW BLACK ELLIPSE AT point*
End Function
我想让一个新线程每xInterval毫秒运行一个flashPoint实例,然后该线程运行killPoint,这将在xFlashtime毫秒后使该点变黑,并在主线程继续执行for循环时死亡


我应该将FlashPoint称为For循环中的任务吗?或者我需要使用线程。创建定时侦听器的线程希望通过优雅的异步避免麻烦?

您应该使用一个计时器,为每个闪点迭代创建单个任务对象,并让回调调用killpoint。我不太确定您在这里尝试做什么。看起来您只是想创建一个闪烁的黄色椭圆?对吗?@user272815不太对。pointArray包含随机点,每xInterval毫秒屏幕上就会出现一个黄色椭圆,在xFlashtime毫秒后,黄色椭圆就会消失,而xFlashtime毫秒可能是在屏幕上出现一个或多个其他椭圆之后。我更新了我的问题,让它更清楚。