Thread.IsBackground プロパティとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > Thread.IsBackground プロパティの意味・解説 

Thread.IsBackground プロパティ

スレッドバックグラウンド スレッドであるかどうかを示す値を取得または設定します

名前空間: System.Threading
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

Dim instance As Thread
Dim value As Boolean

value = instance.IsBackground

instance.IsBackground = value
public bool IsBackground { get;
 set; }
public:
property bool IsBackground {
    bool get ();
    void set (bool value);
}
/** @property */
public boolean get_IsBackground ()

/** @property */
public void set_IsBackground (boolean value)
public function get IsBackground
 () : boolean

public function set IsBackground
 (value : boolean)

プロパティ
このスレッドバックグラウンド スレッドである場合またはバックグラウンド スレッドになる場合trueそれ以外場合false

例外例外
解説解説
使用例使用例

フォアグラウンド スレッドバックグラウンド スレッド動作比較する例を次に示します。この例では、フォアグラウンド スレッドバックグラウンド スレッド作成されます。フォアグラウンド スレッドは、プロセスwhile ループ完了するまでプロセス実行し続けますフォアグラウンド スレッド完了すると、プロセスは、バックグラウンド スレッドwhile ループ完了する前に終了されます。

Imports System
Imports System.Threading

Public Class Test

    <MTAThread> _
    Shared Sub Main()
        Dim shortTest As New
 BackgroundTest(10)
        Dim foregroundThread As New
 Thread(AddressOf shortTest.RunLoop)
        foregroundThread.Name = "ForegroundThread"

        Dim longTest As New
 BackgroundTest(50)
        Dim backgroundThread As New
 Thread(AddressOf longTest.RunLoop)
        backgroundThread.Name = "BackgroundThread"
        backgroundThread.IsBackground = True

        foregroundThread.Start()
        backgroundThread.Start()
    End Sub

End Class

Public Class BackgroundTest

    Dim maxIterations As Integer
 

    Sub New(maximumIterations As
 Integer)
        maxIterations = maximumIterations
    End Sub

    Sub RunLoop()
        Dim threadName As String
 = Thread.CurrentThread.Name

        For i As Integer
 = 0 To maxIterations
            Console.WriteLine("{0} count: {1}", _
                    threadName, i.ToString())
            Thread.Sleep(250)
        Next i

        Console.WriteLine("{0} finished counting.",
 threadName)
    End Sub

End Class
using System;
using System.Threading;

class Test
{
    static void Main()
    {
        BackgroundTest shortTest = new BackgroundTest(10);
        Thread foregroundThread = 
            new Thread(new ThreadStart(shortTest.RunLoop));
        foregroundThread.Name = "ForegroundThread";

        BackgroundTest longTest = new BackgroundTest(50);
        Thread backgroundThread = 
            new Thread(new ThreadStart(longTest.RunLoop));
        backgroundThread.Name = "BackgroundThread";
        backgroundThread.IsBackground = true;

        foregroundThread.Start();
        backgroundThread.Start();
    }
}

class BackgroundTest
{
    int maxIterations;

    public BackgroundTest(int maxIterations)
    {
        this.maxIterations = maxIterations;
    }

    public void RunLoop()
    {
        String threadName = Thread.CurrentThread.Name;
        
        for(int i = 0; i < maxIterations;
 i++)
        {
            Console.WriteLine("{0} count: {1}", 
                threadName, i.ToString());
            Thread.Sleep(250);
        }
        Console.WriteLine("{0} finished counting.", threadName);
    }
}
using namespace System;
using namespace System::Threading;
ref class BackgroundTest
{
private:
   int maxIterations;

public:
   BackgroundTest( int maxIterations )
   {
      this->maxIterations = maxIterations;
   }

   void RunLoop()
   {
      String^ threadName = Thread::CurrentThread->Name;
      for ( int i = 0; i < maxIterations;
 i++ )
      {
         Console::WriteLine( "{0} count: {1}", threadName, i.ToString()
 );
         Thread::Sleep( 250 );

      }
      Console::WriteLine( "{0} finished counting.", threadName );
   }

};

int main()
{
   BackgroundTest^ shortTest = gcnew BackgroundTest( 10 );
   Thread^ foregroundThread = gcnew Thread( gcnew ThreadStart( shortTest, &BackgroundTest::RunLoop
 ) );
   foregroundThread->Name =  "ForegroundThread";
   BackgroundTest^ longTest = gcnew BackgroundTest( 50 );
   Thread^ backgroundThread = gcnew Thread( gcnew ThreadStart( longTest, &BackgroundTest::RunLoop
 ) );
   backgroundThread->Name =  "BackgroundThread";
   backgroundThread->IsBackground = true;
   foregroundThread->Start();
   backgroundThread->Start();
}

import System.*;
import System.Threading.*;
import System.Threading.Thread;

class Test
{
    public static void main(String[]
 args)
    {
        BackgroundTest shortTest = new BackgroundTest(10);
        Thread foregroundThread = new Thread(new
 ThreadStart(shortTest.RunLoop));

        foregroundThread.set_Name("ForegroundThread");

        BackgroundTest longTest = new BackgroundTest(50);
        Thread backgroundThread = new Thread(new
 ThreadStart(longTest.RunLoop));

        backgroundThread.set_Name("BackgroundThread");
        backgroundThread.set_IsBackground(true);
        foregroundThread.Start();
        backgroundThread.Start();
    } //main
} //Test

class BackgroundTest
{
    private int maxIterations;

    public BackgroundTest(int maxIterations)
    {
        this.maxIterations = maxIterations;
    } //BackgroundTest

    public void RunLoop()
    {
        String threadName = Thread.get_CurrentThread().get_Name();

        for (int i = 0; i < maxIterations;
 i++) {
            Console.WriteLine("{0} count: {1}", threadName, String.valueOf(i));
            Thread.Sleep(250);
        }

        Console.WriteLine("{0} finished counting.", threadName);
    } //RunLoop
} //BackgroundTest
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「Thread.IsBackground プロパティ」の関連用語

Thread.IsBackground プロパティのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



Thread.IsBackground プロパティのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2024 Microsoft.All rights reserved.

©2024 GRAS Group, Inc.RSS