HostProtectionAttribute.ExternalThreading 屬性

定義

取得或設定值,表示是否公開外部執行緒。

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

屬性值

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

備註

公開外部執行緒的程式碼會建立或操作本身以外的執行緒,這對主機可能有害。

適用於

另請參閱