HostProtectionAttribute.ExternalThreading 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得或設定值,表示是否公開外部執行緒。
public:
property bool ExternalThreading { bool get(); void set(bool value); };
public bool ExternalThreading { get; set; }
member this.ExternalThreading : bool with get, set
Public Property ExternalThreading As Boolean
屬性值
如果公開外部執行緒則為 true
,否則為 false
。 預設為 false
。
範例
下列程式代碼範例說明搭配 屬性ExternalThreading使用 HostProtectionAttribute 屬性。 這個範例是提供給 類別之較大範例的 HostProtectionAttribute 一部分。
// Use the enumeration flags to indicate that this method exposes synchronization
// and external threading.
[HostProtection(Synchronization=true,ExternalThreading=true)]
static void StartThread()
{
Thread^ t = gcnew Thread( gcnew ThreadStart( WatchFileEvents ) );
// Start the new thread. On a uniprocessor, the thread is not given
// any processor time until the main thread yields the processor.
t->Start();
// Give the new thread a chance to execute.
Thread::Sleep( 1000 );
}
// Use the enumeration flags to indicate that this method exposes
// synchronization and external threading.
[HostProtectionAttribute(Synchronization=true, ExternalThreading=true)]
private static void StartThread()
{
Thread t = new Thread(new ThreadStart(WatchFileEvents));
// Start the new thread. On a uniprocessor, the thread is not given
// any processor time until the main thread yields the processor.
t.Start();
// Give the new thread a chance to execute.
Thread.Sleep(1000);
}
' Use the enumeration flags to indicate that this method exposes
' synchronization and external threading.
<HostProtectionAttribute(Synchronization := True, _
ExternalThreading := True)> _
Private Shared Sub StartThread()
Dim t As New Thread(New ThreadStart(AddressOf WatchFileEvents))
' Start the new thread. On a uniprocessor, the thread is not given
' any processor time until the main thread yields the processor.
t.Start()
' Give the new thread a chance to execute.
Thread.Sleep(1000)
End Sub
備註
公開外部線程的程式代碼會建立或操作本身以外的線程,這可能會對主機造成損害。