You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
1.1 KiB
43 lines
1.1 KiB
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) |
|
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) |
|
|
|
using System; |
|
using System.Threading; |
|
|
|
namespace ICSharpCode.Scripting |
|
{ |
|
public class ThreadSafeScriptingConsoleEvents |
|
{ |
|
// The index into the waitHandles array where the lineReceivedEvent is stored. |
|
int lineReceivedEventIndex = 1; |
|
ManualResetEvent lineReceivedEvent = new ManualResetEvent(false); |
|
ManualResetEvent disposedEvent = new ManualResetEvent(false); |
|
WaitHandle[] waitHandles; |
|
|
|
public ThreadSafeScriptingConsoleEvents() |
|
{ |
|
waitHandles = new WaitHandle[] {disposedEvent, lineReceivedEvent}; |
|
} |
|
|
|
public virtual bool WaitForLine() |
|
{ |
|
int result = WaitHandle.WaitAny(waitHandles); |
|
return lineReceivedEventIndex == result; |
|
} |
|
|
|
public virtual void SetDisposedEvent() |
|
{ |
|
disposedEvent.Set(); |
|
} |
|
|
|
public virtual void SetLineReceivedEvent() |
|
{ |
|
lineReceivedEvent.Set(); |
|
} |
|
|
|
public virtual void ResetLineReceivedEvent() |
|
{ |
|
lineReceivedEvent.Reset(); |
|
} |
|
} |
|
}
|
|
|