G
Guest
Hello, Newsgroupians:
Again, I'm still migrating from Win32 to C#. I've a question regarding some
event handling in C#.
I have created an EventWaitHandle object and pass that to my worker thread.
When the EventWaitHandle is signaled, I would like my secondary thread to
exit. However, in the thread, I also have another event that I would like to
create, which would be much like a CreateWaitableTimer() in Win32.
In Win32, I could use WaitForMultipleEvents() in my while loop...
bool bDone = FALSE;
while (!bDone)
{
int nIndex = WaitForMultipleEvents(...);
if (nIndex == "Terminate Event") // Pseudocode here
{
bDone = true;
}
else if (nIndex == "Timer Event") // Pseudocode here
{
...
}
}
This would work for me, again, in Win32. Now, I'm trying to create the same
code in C#.
I have come up with a solution I believe is similar to my situation.
// This is my thread delegate
public static void Start(object obj)
{
if (obj.GetType() == typeof(EventWaitHandle))
{
EventWaitHandle ewhTerminateEvent = (EventWaitHandle)obj;
Timer t = new System.Threading.Timer(timerCallBack, null, 0, 1000);
ewhTerminateEvent.WaitOne();
}
}
// This is the timer delegate
public static void timerCallBack(object obj)
{
...
}
This, I believe would work; however, is it possible to create a timer that
will not have a callback function? Therefore, I could emulate the Win32
structure that I have described... (IE: I could use WaitHandle.WaitAny())?
Thank you all for your continued support; your help is always appreciated.
Trecius
Again, I'm still migrating from Win32 to C#. I've a question regarding some
event handling in C#.
I have created an EventWaitHandle object and pass that to my worker thread.
When the EventWaitHandle is signaled, I would like my secondary thread to
exit. However, in the thread, I also have another event that I would like to
create, which would be much like a CreateWaitableTimer() in Win32.
In Win32, I could use WaitForMultipleEvents() in my while loop...
bool bDone = FALSE;
while (!bDone)
{
int nIndex = WaitForMultipleEvents(...);
if (nIndex == "Terminate Event") // Pseudocode here
{
bDone = true;
}
else if (nIndex == "Timer Event") // Pseudocode here
{
...
}
}
This would work for me, again, in Win32. Now, I'm trying to create the same
code in C#.
I have come up with a solution I believe is similar to my situation.
// This is my thread delegate
public static void Start(object obj)
{
if (obj.GetType() == typeof(EventWaitHandle))
{
EventWaitHandle ewhTerminateEvent = (EventWaitHandle)obj;
Timer t = new System.Threading.Timer(timerCallBack, null, 0, 1000);
ewhTerminateEvent.WaitOne();
}
}
// This is the timer delegate
public static void timerCallBack(object obj)
{
...
}
This, I believe would work; however, is it possible to create a timer that
will not have a callback function? Therefore, I could emulate the Win32
structure that I have described... (IE: I could use WaitHandle.WaitAny())?
Thank you all for your continued support; your help is always appreciated.
Trecius