I'm thinking of using the EventWaitHandle class to make a thread wait until custom events are raised. However I have never used it before and I could use some suggestions.
Can somebody please tell me what the difference is between using
To make a thread wait and
From what I understand ewh can receive signals to open the thread by using the Set method.
In my case I want to make the thread wait for a signal based on a custom event (An event in Excel). However I only have a single thread to utilize, so by making the thread wait I wont be able to send any signals to it using the Set method (which I would do if certain events occurred).
So I was thinking of using the ewh.WaitOne() method with a timer that loops. After a short time (milliseconds) of making the thread wait, open it back up to see if the event occurred. If event occurred, do x,y and z, else make the thread wait again.
What do you guys think?
By the way JohnH, my previous thread on listening to events with a script was not for a VB script. It's for a .NET script that is manipulating Excel. I just forgot to add the CreateObject("Excel.Application") method in my snippet of code which is why you probably thought it was VB. Sorry.
Can somebody please tell me what the difference is between using
VB.NET:
Dim ewh As EventWaitHandle
ewh = New EventWaitHandle(False, EventResetMode.ManualReset)
ewh.WaitOne()
To make a thread wait and
VB.NET:
Thread.Sleep()
From what I understand ewh can receive signals to open the thread by using the Set method.
VB.NET:
ewh.Set()
In my case I want to make the thread wait for a signal based on a custom event (An event in Excel). However I only have a single thread to utilize, so by making the thread wait I wont be able to send any signals to it using the Set method (which I would do if certain events occurred).
So I was thinking of using the ewh.WaitOne() method with a timer that loops. After a short time (milliseconds) of making the thread wait, open it back up to see if the event occurred. If event occurred, do x,y and z, else make the thread wait again.
What do you guys think?
By the way JohnH, my previous thread on listening to events with a script was not for a VB script. It's for a .NET script that is manipulating Excel. I just forgot to add the CreateObject("Excel.Application") method in my snippet of code which is why you probably thought it was VB. Sorry.