Share yield break vb.net

lythuclap.thanh

New member
#yield BREAK #vb.net #yield Statement #Concurrency #MultithReading ## MIỄN PHÍ BREAK TRONG VB.NET

Năng suất phá vỡ là một tuyên bố cho phép một chức năng đình chỉ thực thi và trả lại kiểm soát cho người gọi.Điều này có thể hữu ích cho các chức năng thực hiện các hoạt động chạy dài, chẳng hạn như I/O hoặc hoạt động mạng, vì nó cho phép người gọi tiếp tục xử lý trong khi chức năng chờ hoàn thành thao tác.

Tuyên bố phá vỡ lợi suất được sử dụng cùng với câu lệnh trả về lợi suất.Câu lệnh trả về lợi suất được sử dụng để trả về một giá trị từ một hàm và câu lệnh break lãi được sử dụng để chấm dứt hàm mà không trả lại giá trị.

Sau đây là một ví dụ về chức năng sử dụng câu lệnh Break Mole Break:

`` `vb.net
Hàm dowork () như ienumerere (của số nguyên)
Dim I As Integer

Cho i = 1 đến 10
'Làm một số công việc ở đây

Nếu tôi = 5 thì
'Năng suất phá vỡ để chấm dứt chức năng
Năng suất phá vỡ
Kết thúc nếu

Năng suất i
Kế tiếp
Hàm cuối
`` `

Khi chức năng này được gọi, nó sẽ lặp lại từ 1 đến 10, thực hiện một số công việc trên mỗi lần lặp.Tuy nhiên, nếu số lần lặp đạt 5, chức năng sẽ mang lại sự phá vỡ và chấm dứt.Điều này sẽ cho phép người gọi tiếp tục xử lý trong khi chức năng chờ đợi các lần lặp còn lại hoàn tất.

Tuyên bố phá vỡ lợi suất có thể được sử dụng để thực hiện một loạt các mẫu đồng thời và đa luồng.Để biết thêm thông tin, vui lòng xem các tài nguyên sau:

* [Năng suất phá vỡ trong vb.net] (https://docs.microsoft.com/en-us/dotnet/visual-basic/language-reference/statements/yield-break)
* [Đồng thời và đa luồng trong vb.net] (https://docs.microsoft.com/en-us/dotnet/visual-basic/programming-guide/concurrency/)
=======================================
#yield Break #vb.net #yield Statement #Concurrency #MultithReading ##Yield Break in VB.NET

Yield break is a statement that allows a function to suspend execution and return control to the caller. This can be useful for functions that perform long-running operations, such as I/O or network operations, as it allows the caller to continue processing while the function waits for the operation to complete.

The yield break statement is used in conjunction with the yield return statement. The yield return statement is used to return a value from a function, and the yield break statement is used to terminate the function without returning a value.

The following is an example of a function that uses the yield break statement:

```vb.net
Function DoWork() As IEnumerable(Of Integer)
Dim i As Integer

For i = 1 To 10
' Do some work here

If i = 5 Then
' Yield break to terminate the function
Yield Break
End If

Yield i
Next
End Function
```

When this function is called, it will iterate from 1 to 10, performing some work on each iteration. However, if the iteration count reaches 5, the function will yield break and terminate. This will allow the caller to continue processing while the function waits for the remaining iterations to complete.

The yield break statement can be used to implement a variety of concurrency and multithreading patterns. For more information, please see the following resources:

* [Yield Break in VB.NET](https://docs.microsoft.com/en-us/dotnet/visual-basic/language-reference/statements/yield-break)
* [Concurrency and Multithreading in VB.NET](https://docs.microsoft.com/en-us/dotnet/visual-basic/programming-guide/concurrency/)
 
Join Telegram ToolsKiemTrieuDoGroup
Back
Top