ProgressChangedEventArgs.ProgressPercentage 属性
定义
获取异步任务的进度百分比。Gets the asynchronous task progress percentage.
public:
property int ProgressPercentage { int get(); };
public int ProgressPercentage { get; }
member this.ProgressPercentage : int
Public ReadOnly Property ProgressPercentage As Integer
属性值
指示异步任务进度的百分比值。A percentage value indicating the asynchronous task progress.
示例
下面的代码示例演示如何使用此成员。The following code example demonstrates the use of this member. 在此示例中,事件处理程序报告事件的发生 PictureBox.LoadProgressChanged 。In the example, an event handler reports on the occurrence of the PictureBox.LoadProgressChanged event. 此报表可帮助你了解何时发生事件,并可帮助你进行调试。This report helps you to learn when the event occurs and can assist you in debugging. 若要报告多个事件或频繁发生的事件,请考虑 MessageBox.Show Console.WriteLine 将消息替换为多行或将其追加到多行 TextBox 。To report on multiple events or on events that occur frequently, consider replacing MessageBox.Show with Console.WriteLine or appending the message to a multiline TextBox.
若要运行示例代码,请将其粘贴到包含名为的类型的实例的项目中 PictureBox PictureBox1 。To run the example code, paste it into a project that contains an instance of type PictureBox named PictureBox1. 然后,确保事件处理程序与事件相关联 PictureBox.LoadProgressChanged 。Then ensure that the event handler is associated with the PictureBox.LoadProgressChanged event.
private void PictureBox1_LoadProgressChanged(Object sender, ProgressChangedEventArgs e) {
System.Text.StringBuilder messageBoxCS = new System.Text.StringBuilder();
messageBoxCS.AppendFormat("{0} = {1}", "ProgressPercentage", e.ProgressPercentage );
messageBoxCS.AppendLine();
messageBoxCS.AppendFormat("{0} = {1}", "UserState", e.UserState );
messageBoxCS.AppendLine();
MessageBox.Show(messageBoxCS.ToString(), "LoadProgressChanged Event" );
}
Private Sub PictureBox1_LoadProgressChanged(sender as Object, e as ProgressChangedEventArgs) _
Handles PictureBox1.LoadProgressChanged
Dim messageBoxVB as New System.Text.StringBuilder()
messageBoxVB.AppendFormat("{0} = {1}", "ProgressPercentage", e.ProgressPercentage)
messageBoxVB.AppendLine()
messageBoxVB.AppendFormat("{0} = {1}", "UserState", e.UserState)
messageBoxVB.AppendLine()
MessageBox.Show(messageBoxVB.ToString(),"LoadProgressChanged Event")
End Sub
注解
ProgressPercentage属性确定异步任务完成的百分比。The ProgressPercentage property determines what percentage of an asynchronous task has been completed.
适用于
另请参阅
- BackgroundWorker
- 如何:实现支持基于事件的异步模式的组件How to: Implement a Component that Supports the Event-based Asynchronous Pattern
- 如何:在后台运行操作How to: Run an Operation in the Background
- 如何:实现使用后台操作的窗体How to: Implement a Form That Uses a Background Operation
- 如何:使用支持基于事件的异步模式的组件How to: Use Components that Support the Event-based Asynchronous Pattern