001 002 003 004 005 006 007 008 009 010
011 012 013 014 015 016 017 018 019 020
021 022 023 024 025 026 027 028 029 030
031 032 033 034 035 036 037 038 039 040
041 042 043 044 045 046 047 048 049 050
051 052 053 054 055 056 057 058 059 060
061 062 063 064 065 066 067 068 069
|
Public Class CalculatingApplication
Inherits System.Windows.Forms.ApplicationContext
Public Sub New()
MyBase.New()
End Sub
Public Sub Start()
' 計算を行うスレッドを起動する
Dim thread As New System.Threading.Thread(AddressOf Calculate)
thread.Start()
End Sub
Private Sub Calculate()
Console.WriteLine("計算を開始します。")
Dim count As Integer = 0
Do
count += 1
System.Threading.Thread.Sleep(50)
Loop Until (100 < count)
' スレッドのメッセージループを終了する
MyClass.ExitThread()
Console.WriteLine("計算が終了しました。")
End Sub
Protected Overrides Sub ExitThreadCore()
Console.WriteLine("スレッドのメッセージループを終了します。")
MyBase.ExitThreadCore()
End Sub
End Class
Public Class MainClass
Public Shared Sub Main()
Dim app As New CalculatingApplication
' 計算を開始する
app.Start()
Console.WriteLine("現在のスレッドでメッセージループが開始されます。")
' CalculatingApplicationクラスのインスタンスを使用してアプリケーションを起動する
System.Windows.Forms.Application.Run(app)
Console.WriteLine("スレッドのメッセージループは終了しました。")
End Sub
End Class
|
001 002 003 004 005 006 007 008 009 010
011 012 013 014 015 016 017 018 019 020
021 022 023 024 025 026 027 028 029 030
031 032 033 034 035 036 037 038 039 040
041 042 043 044 045 046 047 048 049 050
051 052 053 054 055 056 057
|
public class CalculatingApplication : System.Windows.Forms.ApplicationContext
{
public CalculatingApplication() : base() {}
public void Start()
{
// 計算を行うスレッドを起動する
System.Threading.Thread thread = new System.Threading.Thread( new System.Threading.ThreadStart( Calculate ) );
thread.Start();
}
private void Calculate()
{
Console.WriteLine( "計算を開始します。" );
int count = 0;
do
{
count += 1;
System.Threading.Thread.Sleep( 50 );
} while ( !( 100 < count ) );
// スレッドのメッセージループを終了する
this.ExitThread();
Console.WriteLine( "計算が終了しました。" );
}
protected override void ExitThreadCore()
{
Console.WriteLine( "スレッドのメッセージループを終了します。" );
base.ExitThreadCore();
}
}
public class MainClass
{
public static void Main()
{
CalculatingApplication app = new CalculatingApplication();
// 計算を開始する
app.Start();
Console.WriteLine( "現在のスレッドでメッセージループが開始されます。" );
// CalculatingApplicationクラスのインスタンスを使用してアプリケーションを起動する
System.Windows.Forms.Application.Run( app );
Console.WriteLine( "スレッドのメッセージループは終了しました。" );
}
}
|