WindowsFormsApplicationBase.DoEvents メソッド
定義
メッセージ キューに現在ある Windows メッセージをすべて処理します。Processes all Windows messages currently in the message queue.
public:
void DoEvents();
public void DoEvents ();
member this.DoEvents : unit -> unit
Public Sub DoEvents ()
例
この例では、My.Application.DoEvents
メソッドを使用して、TextBox1
の UI を更新できるようにします。This example uses the My.Application.DoEvents
method to allow the UI for TextBox1
to update.
Private Sub TestDoEvents()
For i As Integer = 0 To 10000
TextBox1.Text = i.ToString
My.Application.DoEvents()
Next
End Sub
このコードは、Text
プロパティを持つ TextBox1
コンポーネントを含むフォームにある必要があります。This code should be in a form that has a TextBox1
component with a Text
property.
注釈
My.Application.DoEvents
メソッドを使用すると、コードの実行中に発生する可能性のある他のイベントをアプリケーションで処理できます。The My.Application.DoEvents
method allows your application to handle other events that might be raised while you code runs. My.Application.DoEvents
メソッドは、DoEvents メソッドと同じ動作をします。The My.Application.DoEvents
method has the same behavior as the DoEvents method.
Windows フォームアプリケーションを実行すると、新しいフォームが作成され、イベントが処理されるまで待機します。When you run a Windows Forms application, it creates a new form, which then waits for events to be handled. ボタンクリックなどのイベントをフォームが処理するたびに、そのイベントに関連付けられているすべてのコードが処理されます。Each time the form handles an event, such as a button click, it processes all the code associated with that event. 他のすべてのイベントは、キューで待機します。All other events wait in the queue. コードによってイベントが処理されても、アプリケーションは応答しません。While your code handles the event, your application does not respond. たとえば、別のウィンドウが上にドラッグされている場合、ウィンドウは再描画されません。For example, the window does not repaint if another window is dragged on top.
コードで My.Application.DoEvents
を呼び出すと、アプリケーションは他のイベントを処理できます。If you call My.Application.DoEvents
in your code, your application can handle the other events. たとえば、コードでループ内の ListBox にデータを追加し、ループの各ステップの後に My.Application.DoEvents
を呼び出すと、別のウィンドウをドラッグしたときにフォームが再描画されます。For example, if your code adds data to a ListBox in a loop, and after each step of the loop it calls My.Application.DoEvents
, your form repaints when another window is dragged over it. コードから My.Application.DoEvents
を削除すると、ボタンのクリックイベントハンドラーの実行が完了するまでフォームは再描画されません。If you remove My.Application.DoEvents
from your code, your form will not repaint until the click event handler of the button is finished executing.
通常、このメソッドをループで使用してメッセージを処理します。Typically, you use this method in a loop to process messages.
注意
My.Application.DoEvents
メソッドは、フォームとまったく同じ方法でイベントを処理しません。The My.Application.DoEvents
method does not process events in exactly the same way as the form does. マルチスレッドを使用して、フォームがイベントを直接処理するようにします。Use multithreading to make the form directly handle the events. 詳細については、「マルチスレッドアプリケーション」を参照してください。For more information, see Multithreaded Applications.
注意事項
ユーザーインターフェイス (UI) イベントを処理するメソッドが My.Application.DoEvents
メソッドを呼び出すと、メソッドが完了する前に再入力されている可能性があります。If a method that handles a user interface (UI) event calls the My.Application.DoEvents
method, the method might be re-entered before it finishes. これは、My.Application.DoEvents
メソッドによって Windows メッセージが処理され、Windows メッセージによってイベントが発生する可能性があるために発生する可能性があります。This can happen because the My.Application.DoEvents
method processes Windows messages, and Windows messages can raise events.
次の表に、My.Application.DoEvents
メソッドに関連するタスクの例を示します。The following table lists an example of a task involving the My.Application.DoEvents
method.
終了To | 解決方法については、See |
---|---|
フォームが UI 入力に応答している間に応答することを許可するAllow a form to respond to UI input while busy | チュートリアル : イベントの処理Walkthrough: Handling Events |
プロジェクトの種類別の可用性Availability by Project Type
プロジェクトの種類Project type | 使用可能Available |
---|---|
Windows フォーム アプリケーションWindows Forms Application | はいYes |
クラス ライブラリClass Library | いいえNo |
コンソール アプリケーションConsole Application | いいえNo |
Windows フォーム コントロール ライブラリWindows Forms Control Library | いいえNo |
Web コントロールライブラリWeb Control Library | いいえNo |
Windows サービスWindows Service | いいえNo |
Web サイトWeb Site | いいえNo |
セキュリティ
FileIOPermission
ファイルとフォルダーにアクセスする機能を制御します。Controls the ability to access files and folders. Unrestricted (関連する列挙体)Associated enumeration: Unrestricted.
UIPermission
ユーザー インターフェイスとクリップボードに関連したアクセス許可を制御します。Controls the permissions related to user interfaces and the Clipboard. AllWindows (関連する列挙体)Associated enumeration: AllWindows.