Home
Discussion Forums
Tutorials & Source Code
Developer Blogs
Developer Events
Developer Jobs
Labs
We need you!
We're working hard on the next version of Developer Fusion -
Let us know
what you think we should be up to!
The Labs
\
Source Viewer
\
SSCLI
\
System.Threading
\ CancellationSignal
Object Browser
Solution Explorer
SSCLI
Expand
Microsoft.Win32
Expand
Microsoft.Win32.SafeHandles
Expand
System
Expand
System.Runtime.Hosting
Expand
System.Runtime.InteropServices
Expand
System.Runtime.CompilerServices
Expand
System.Collections
Expand
System.Collections.Generic
Expand
System.Collections.ObjectModel
Expand
System.Configuration.Assemblies
Expand
System.Diagnostics
Expand
System.Diagnostics.CodeAnalysis
Expand
System.Diagnostics.SymbolStore
Expand
System.Globalization
Expand
System.IO
Expand
System.IO.IsolatedStorage
Expand
System.Reflection
Expand
System.Reflection.Cache
Expand
System.Reflection.Emit
Expand
System.Resources
Expand
System.Runtime
Expand
System.Runtime.InteropServices.Expando
Expand
System.Runtime.ConstrainedExecution
Expand
System.Runtime.Remoting.Activation
Expand
System.Runtime.Remoting.Messaging
Expand
System.Runtime.Remoting.Channels
Expand
System.Runtime.Remoting.Lifetime
Expand
System.Runtime.Remoting
Expand
System.Runtime.Remoting.Contexts
Expand
System.Runtime.Remoting.Proxies
Expand
System.Runtime.Remoting.Metadata
Expand
System.Runtime.Remoting.Metadata.W3cXsd2001
Expand
System.Runtime.Remoting.Services
Expand
System.Runtime.Serialization
Expand
System.Runtime.Serialization.Formatters
Expand
System.Runtime.Serialization.Formatters.Binary
Expand
System.Runtime.Versioning
Expand
System.Security
Expand
System.Security.Cryptography
Expand
System.Security.Cryptography.X509Certificates
Expand
System.Security.Permissions
Expand
System.Security.Policy
Expand
System.Security.Principal
Expand
System.Security.Util
Expand
System.Text
Expand
System.Threading
Expand
_IOCompletionCallback
Expand
_ThreadPoolWaitCallback
Expand
_ThreadPoolWaitOrTimerCallback
Expand
_TimerCallback
Expand
AbandonedMutexException
Expand
AsyncFlowControl
Expand
AutoResetEvent
Expand
CancellationRegion
Expand
CancellationSignal
Cancel()
CancellationSignal()
CancellationSignal(bool)
CancelRequested()
CheckSupportsCancelSyncIO()
Thread()
Expand
CompressedStack
Expand
CompressedStackRunData
Expand
CompressedStackSwitcher
Expand
DomainCompressedStack
Expand
EventResetMode
Expand
EventWaitHandle
Expand
ExceptionType
Expand
ExecutionContext
Expand
ExecutionContextRunData
Expand
ExecutionContextSwitcher
Expand
HostExecutionContext
Expand
HostExecutionContextManager
Expand
HostExecutionContextSwitcher
Expand
Interlocked
Expand
IUnknownSafeHandle
Expand
LockCookie
Expand
ManualResetEvent
Expand
Monitor
Expand
Mutex
Expand
MutexCleanupInfo
Expand
NativeOverlapped
Expand
Overlapped
Expand
OverlappedData
Expand
OverlappedDataCache
Expand
OverlappedDataCacheLine
Expand
ReaderWriterLock
Expand
RegisteredWaitHandle
Expand
RegisteredWaitHandleSafe
Expand
SafeCompressedStackHandle
Expand
Semaphore
Expand
SemaphoreFullException
Expand
StackCrawlMark
Expand
SynchronizationContext
Expand
SynchronizationContextProperties
Expand
SynchronizationContextSwitcher
Expand
SynchronizationLockException
Expand
Thread
Expand
ThreadAbortException
Expand
ThreadHelper
Expand
ThreadInterruptedException
Expand
ThreadPool
Expand
ThreadPriority
Expand
ThreadStartException
Expand
ThreadState
Expand
ThreadStateException
Expand
Timeout
Expand
Timer
Expand
TimerBase
Expand
WaitHandle
Expand
WaitHandleCannotBeOpenedException
Expand
System.Runtime.Remoting.Channels.Http
Expand
System.Runtime.Remoting.Channels.Tcp
Expand
System.Runtime.Remoting.MetadataServices
Expand
System.Runtime.Serialization.Formatters.Soap.Xml
Expand
System.Runtime.Serialization.Formatters.Soap
Expand
Microsoft.Tools.Caspol
Expand
Microsoft.Tools.Build
Expand
Microsoft.CSharp
Expand
System.CodeDom
Expand
System.CodeDom.Compiler
Expand
System.Collections.Specialized
Expand
System.ComponentModel
Expand
System.ComponentModel.Design
Expand
System.ComponentModel.Design.Serialization
Expand
System.Configuration
Expand
System.Web
Expand
System.Configuration.Provider
Expand
System.Configuration.Internal
Expand
System.Internal
Expand
System.Windows.Forms
Expand
System.Net
Expand
System.Net.Sockets
Expand
System.Net.NetworkInformation
Expand
System.Net.ComImports
Expand
System.Net.Security
Expand
System.Net.Cache
Expand
System.Net.Configuration
Expand
System.Text.RegularExpressions
Expand
System.Tools
Expand
System.IO.Compression
Expand
System.IO.Ports
Expand
System.Security.AccessControl
Expand
System.Xml
Expand
System.Xml.XPath.DataBinding
Expand
System.Xml.Schema
Expand
System.Xml.Serialization
Expand
System.Xml.Serialization.Advanced
Expand
System.Xml.Serialization.Configuration
Expand
System.Xml.XPath
Expand
System.Xml.Xsl
Expand
System.Xml.Xsl.IlGen
Expand
System.Xml.Xsl.Qil
Expand
System.Xml.Xsl.Runtime
Expand
System.Xml.Xsl.XPath
Expand
System.Xml.Xsl.Xslt
Expand
System.Xml.Xsl.XsltOld
Expand
System.Xml.Xsl.XsltOld.Debugger
Expand
Microsoft.JScript
Expand
Microsoft.Vsa
Expand
Microsoft.JScript.Vsa
C#
VB.NET
// ==++==
//
//
// Copyright (c) 2006 Microsoft Corporation. All rights reserved.
//
// The use and distribution terms for this software are contained in the file
// named license.txt, which can be found in the root of this distribution.
// By using this software in any fashion, you are agreeing to be bound by the
// terms of this license.
//
// You must not remove this notice, or any other, from this software.
//
//
// ==--==
/*============================================================
**
** Class: CancellationSignal
**
**
** Purpose: Defines an identifier to ensure you can only
** cancel synchronous IO requests that you were expecting to
** cancel.
**
**
===========================================================*/
using
System.IO
;
using
System.Security.Permissions
;
using
System.Collections.Generic
;
using
System.Runtime.ConstrainedExecution
;
using
Microsoft.Win32
;
namespace
System.Threading
{
public
sealed
class
CancellationSignal
{
// Warning - Thread contains a stack of CancellationSignals, which
// places a restriction on this class. All types used within a
// CancellationSignal must be AppDomain-agile. Otherwise, we will
// bleed objects across appdomains, just as we do with CultureInfo
// today. Be very careful about adding new members here. We've
// sealed the class to prevent users from accidentally causing this
// problem for themselves in subclasses of CancellationSignal.
private
Thread
_thread;
private
bool
_cancelable;
private
bool
_wasCancelRequested;
private
static
bool
SupportsCancelSyncIOChecked;
private
static
bool
OSSupportsCancelSyncIO;
[ReliabilityContract(Consistency.MayCorruptInstance, Cer.MayFail)]
public
CancellationSignal()
{
_cancelable =
true
;
}
[ReliabilityContract(Consistency.MayCorruptInstance, Cer.MayFail)]
internal
CancellationSignal(
bool
cancelable)
{
_cancelable = cancelable;
}
[HostProtection(ExternalThreading =
true
)]
[SecurityPermission(SecurityAction.LinkDemand, UnmanagedCode =
true
)]
public
void
Cancel()
{
_wasCancelRequested =
true
;
throw
new
PlatformNotSupportedException
();
}
private
static
void
CheckSupportsCancelSyncIO()
{
OSSupportsCancelSyncIO =
false
;
SupportsCancelSyncIOChecked =
true
;
}
// To allow CPU-intensive tasks to use our cancellation model to
// opt into cancellation via polling. We could also use this in
// select places to help avoid races inherent in the OS's
// cancellation model, such as attempting to cancel CopyFile while
// it is in the middle of some CPU-intensive calculation instead of
// blocked waiting for IO.
// Note that if you cancel one region, it should cancel any nested
// cancellable regions. See Cancel for this logic.
public
bool
CancelRequested {
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
get {
return
_wasCancelRequested; }
}
internal
Thread
Thread {
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
get {
return
_thread; }
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
set {
if
(_thread !=
null
&& value !=
null
)
throw
new
InvalidOperationException
(Environment.GetResourceString("InvalidOperation_CancellationSignalReuse"));
_thread = value;
}
}
}
}
Developer Fusion