-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Expand file tree
/
Copy pathBackgroundWorker.xml
More file actions
1265 lines (1151 loc) · 94.7 KB
/
BackgroundWorker.xml
File metadata and controls
1265 lines (1151 loc) · 94.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<Type Name="BackgroundWorker" FullName="System.ComponentModel.BackgroundWorker">
<TypeSignature Language="C#" Value="public class BackgroundWorker : IDisposable" FrameworkAlternate="dotnet-uwp-10.0;netcore-1.0;netcore-1.1" />
<TypeSignature Language="ILAsm" Value=".class public auto ansi beforefieldinit BackgroundWorker extends System.Object implements class System.IDisposable" FrameworkAlternate="dotnet-uwp-10.0;netcore-1.0;netcore-1.1" />
<TypeSignature Language="DocId" Value="T:System.ComponentModel.BackgroundWorker" />
<TypeSignature Language="VB.NET" Value="Public Class BackgroundWorker
Implements IDisposable" FrameworkAlternate="dotnet-uwp-10.0;netcore-1.0;netcore-1.1" />
<TypeSignature Language="F#" Value="type BackgroundWorker = class
 interface IDisposable" FrameworkAlternate="dotnet-uwp-10.0;netcore-1.0;netcore-1.1" />
<TypeSignature Language="C++ CLI" Value="public ref class BackgroundWorker : IDisposable" FrameworkAlternate="dotnet-uwp-10.0;netcore-1.0;netcore-1.1" />
<TypeSignature Language="C#" Value="public class BackgroundWorker : System.ComponentModel.Component" FrameworkAlternate="net-10.0;net-11.0;net-5.0;net-6.0;net-7.0;net-8.0;net-9.0;netcore-2.0;netcore-2.1;netcore-2.2;netcore-3.0;netcore-3.1;netframework-2.0;netframework-3.0;netframework-3.5;netframework-4.0;netframework-4.5;netframework-4.5.1;netframework-4.5.2;netframework-4.6;netframework-4.6.1;netframework-4.6.2;netframework-4.7;netframework-4.7.1;netframework-4.7.2;netframework-4.8;netframework-4.8.1;netstandard-2.0;netstandard-2.1" />
<TypeSignature Language="ILAsm" Value=".class public auto ansi beforefieldinit BackgroundWorker extends System.ComponentModel.Component" FrameworkAlternate="net-10.0;net-11.0;net-5.0;net-6.0;net-7.0;net-8.0;net-9.0;netcore-2.0;netcore-2.1;netcore-2.2;netcore-3.0;netcore-3.1;netframework-2.0;netframework-3.0;netframework-3.5;netframework-4.0;netframework-4.5;netframework-4.5.1;netframework-4.5.2;netframework-4.6;netframework-4.6.1;netframework-4.6.2;netframework-4.7;netframework-4.7.1;netframework-4.7.2;netframework-4.8;netframework-4.8.1;netstandard-2.0;netstandard-2.1" />
<TypeSignature Language="VB.NET" Value="Public Class BackgroundWorker
Inherits Component" FrameworkAlternate="net-10.0;net-11.0;net-5.0;net-6.0;net-7.0;net-8.0;net-9.0;netcore-2.0;netcore-2.1;netcore-2.2;netcore-3.0;netcore-3.1;netframework-2.0;netframework-3.0;netframework-3.5;netframework-4.0;netframework-4.5;netframework-4.5.1;netframework-4.5.2;netframework-4.6;netframework-4.6.1;netframework-4.6.2;netframework-4.7;netframework-4.7.1;netframework-4.7.2;netframework-4.8;netframework-4.8.1;netstandard-2.0;netstandard-2.1" />
<TypeSignature Language="F#" Value="type BackgroundWorker = class
 inherit Component" FrameworkAlternate="net-10.0;net-11.0;net-5.0;net-6.0;net-7.0;net-8.0;net-9.0;netcore-2.0;netcore-2.1;netcore-2.2;netcore-3.0;netcore-3.1;netframework-2.0;netframework-3.0;netframework-3.5;netframework-4.0;netframework-4.5;netframework-4.5.1;netframework-4.5.2;netframework-4.6;netframework-4.6.1;netframework-4.6.2;netframework-4.7;netframework-4.7.1;netframework-4.7.2;netframework-4.8;netframework-4.8.1;netstandard-2.0;netstandard-2.1" />
<TypeSignature Language="C++ CLI" Value="public ref class BackgroundWorker : System::ComponentModel::Component" FrameworkAlternate="net-10.0;net-11.0;net-5.0;net-6.0;net-7.0;net-8.0;net-9.0;netcore-2.0;netcore-2.1;netcore-2.2;netcore-3.0;netcore-3.1;netframework-2.0;netframework-3.0;netframework-3.5;netframework-4.0;netframework-4.5;netframework-4.5.1;netframework-4.5.2;netframework-4.6;netframework-4.6.1;netframework-4.6.2;netframework-4.7;netframework-4.7.1;netframework-4.7.2;netframework-4.8;netframework-4.8.1;netstandard-2.0;netstandard-2.1" />
<AssemblyInfo>
<AssemblyName>System.ComponentModel.EventBasedAsync</AssemblyName>
<AssemblyVersion>4.0.10.0</AssemblyVersion>
<AssemblyVersion>4.1.0.0</AssemblyVersion>
<AssemblyVersion>4.1.1.0</AssemblyVersion>
<AssemblyVersion>4.1.2.0</AssemblyVersion>
<AssemblyVersion>5.0.0.0</AssemblyVersion>
<AssemblyVersion>6.0.0.0</AssemblyVersion>
<AssemblyVersion>7.0.0.0</AssemblyVersion>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
<AssemblyVersion>9.0.0.0</AssemblyVersion>
<AssemblyVersion>10.0.0.0</AssemblyVersion>
<AssemblyVersion>11.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.0.5.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>netstandard</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.1.0.0</AssemblyVersion>
</AssemblyInfo>
<TypeForwardingChain>
<TypeForwarding From="netstandard" FromVersion="2.1.0.0" To="System.ComponentModel.EventBasedAsync" ToVersion="10.0.0.0" FrameworkAlternate="net-10.0" />
<TypeForwarding From="netstandard" FromVersion="2.1.0.0" To="System.ComponentModel.EventBasedAsync" ToVersion="11.0.0.0" FrameworkAlternate="net-11.0" />
<TypeForwarding From="netstandard" FromVersion="2.1.0.0" To="System.ComponentModel.EventBasedAsync" ToVersion="5.0.0.0" FrameworkAlternate="net-5.0" />
<TypeForwarding From="netstandard" FromVersion="2.1.0.0" To="System.ComponentModel.EventBasedAsync" ToVersion="6.0.0.0" FrameworkAlternate="net-6.0" />
<TypeForwarding From="netstandard" FromVersion="2.1.0.0" To="System.ComponentModel.EventBasedAsync" ToVersion="7.0.0.0" FrameworkAlternate="net-7.0" />
<TypeForwarding From="netstandard" FromVersion="2.1.0.0" To="System.ComponentModel.EventBasedAsync" ToVersion="8.0.0.0" FrameworkAlternate="net-8.0" />
<TypeForwarding From="netstandard" FromVersion="2.1.0.0" To="System.ComponentModel.EventBasedAsync" ToVersion="9.0.0.0" FrameworkAlternate="net-9.0" />
</TypeForwardingChain>
<Base>
<BaseTypeName>System.Object</BaseTypeName>
<BaseTypeName FrameworkAlternate="net-10.0;net-11.0;net-5.0;net-6.0;net-7.0;net-8.0;net-9.0;netcore-2.0;netcore-2.1;netcore-2.2;netcore-3.0;netcore-3.1;netframework-2.0;netframework-3.0;netframework-3.5;netframework-4.0;netframework-4.5;netframework-4.5.1;netframework-4.5.2;netframework-4.6;netframework-4.6.1;netframework-4.6.2;netframework-4.7;netframework-4.7.1;netframework-4.7.2;netframework-4.8;netframework-4.8.1;netstandard-2.0;netstandard-2.1">System.ComponentModel.Component</BaseTypeName>
</Base>
<Interfaces>
<Interface FrameworkAlternate="dotnet-uwp-10.0;netcore-1.0;netcore-1.1">
<InterfaceName>System.IDisposable</InterfaceName>
</Interface>
</Interfaces>
<Attributes>
<Attribute FrameworkAlternate="net-10.0;net-11.0;net-8.0;net-9.0">
<AttributeName Language="C#">[System.Runtime.CompilerServices.Nullable(0)]</AttributeName>
<AttributeName Language="F#">[<System.Runtime.CompilerServices.Nullable(0)>]</AttributeName>
</Attribute>
<Attribute FrameworkAlternate="netframework-2.0;netframework-3.0;netframework-3.5;netframework-4.0;netframework-4.5;netframework-4.5.1;netframework-4.5.2;netframework-4.6;netframework-4.6.1;netframework-4.6.2;netframework-4.7;netframework-4.7.1;netframework-4.7.2;netframework-4.8;netframework-4.8.1;netstandard-2.0;netstandard-2.1">
<AttributeName Language="C#">[System.ComponentModel.DefaultEvent("DoWork")]</AttributeName>
<AttributeName Language="F#">[<System.ComponentModel.DefaultEvent("DoWork")>]</AttributeName>
</Attribute>
</Attributes>
<Docs>
<summary>Executes an operation on a separate thread.</summary>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
The <xref:System.ComponentModel.BackgroundWorker> class allows you to run an operation on a separate, dedicated thread. Time-consuming operations like downloads and database transactions can cause your user interface (UI) to seem as though it has stopped responding while they are running. When you want a responsive UI and you are faced with long delays associated with such operations, the <xref:System.ComponentModel.BackgroundWorker> class provides a convenient solution.
To execute a time-consuming operation in the background, create a <xref:System.ComponentModel.BackgroundWorker> and listen for events that report the progress of your operation and signal when your operation is finished. You can create the <xref:System.ComponentModel.BackgroundWorker> programmatically or you can drag it onto your form from the **Components** tab of the **Toolbox**. If you create the <xref:System.ComponentModel.BackgroundWorker> in the Windows Forms Designer, it will appear in the Component Tray, and its properties will be displayed in the Properties window.
To set up for a background operation, add an event handler for the <xref:System.ComponentModel.BackgroundWorker.DoWork> event. Call your time-consuming operation in this event handler. To start the operation, call <xref:System.ComponentModel.BackgroundWorker.RunWorkerAsync*>. To receive notifications of progress updates, handle the <xref:System.ComponentModel.BackgroundWorker.ProgressChanged> event. To receive a notification when the operation is completed, handle the <xref:System.ComponentModel.BackgroundWorker.RunWorkerCompleted> event.
> [!NOTE]
> You must be careful not to manipulate any user-interface objects in your <xref:System.ComponentModel.BackgroundWorker.DoWork> event handler. Instead, communicate to the user interface through the <xref:System.ComponentModel.BackgroundWorker.ProgressChanged> and <xref:System.ComponentModel.BackgroundWorker.RunWorkerCompleted> events.
>
> <xref:System.ComponentModel.BackgroundWorker> events are not marshaled across <xref:System.AppDomain> boundaries. Do not use a <xref:System.ComponentModel.BackgroundWorker> component to perform multithreaded operations in more than one <xref:System.AppDomain>.
If your background operation requires a parameter, call <xref:System.ComponentModel.BackgroundWorker.RunWorkerAsync*> with your parameter. Inside the <xref:System.ComponentModel.BackgroundWorker.DoWork> event handler, you can extract the parameter from the <xref:System.ComponentModel.DoWorkEventArgs.Argument?displayProperty=nameWithType> property.
For more information about <xref:System.ComponentModel.BackgroundWorker>, see [How to: Run an Operation in the Background](/dotnet/framework/winforms/controls/how-to-run-an-operation-in-the-background).
## Examples
The following code example demonstrates the basics of the <xref:System.ComponentModel.BackgroundWorker> class for executing a time-consuming operation asynchronously. The following illustration shows an example of the output.

To try this code, create a Windows Forms application. Add a <xref:System.Windows.Forms.Label> control named `resultLabel` and add two <xref:System.Windows.Forms.Button> controls named `startAsyncButton` and `cancelAsyncButton`. Create <xref:System.Windows.Forms.Control.Click> event handlers for both buttons. From the **Components** tab of the Toolbox, add a <xref:System.ComponentModel.BackgroundWorker> component named `backgroundWorker1`. Create <xref:System.ComponentModel.BackgroundWorker.DoWork>, <xref:System.ComponentModel.BackgroundWorker.ProgressChanged>, and <xref:System.ComponentModel.BackgroundWorker.RunWorkerCompleted> event handlers for the <xref:System.ComponentModel.BackgroundWorker>. In the code for the form, replace the existing code with the following code.
:::code language="csharp" source="~/snippets/csharp/System.ComponentModel/BackgroundWorker/Overview/form1.cs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/System.ComponentModel/BackgroundWorker/Overview/form1.vb" id="Snippet1":::
The following code example demonstrates the use of the <xref:System.ComponentModel.BackgroundWorker> class for executing a time-consuming operation asynchronously. The following illustration shows an example of the output.

The operation computes the selected Fibonacci number, reports progress updates as the calculation proceeds, and permits a pending calculation to be canceled.
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_Winforms/System.ComponentModel.BackgroundWorker/CPP/fibonacciform.cpp" id="Snippet1":::
:::code language="csharp" source="~/snippets/csharp/System.ComponentModel/BackgroundWorker/Overview/fibonacciform.cs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/System.ComponentModel/BackgroundWorker/Overview/fibonacciform.vb" id="Snippet1":::
]]></format>
</remarks>
<related type="Article" href="/dotnet/framework/winforms/controls/how-to-run-an-operation-in-the-background">How to: Run an Operation in the Background</related>
<related type="Article" href="/dotnet/standard/threading/managed-threading-best-practices">Managed Threading Best Practices</related>
<related type="Article" href="/dotnet/framework/winforms/controls/how-to-download-a-file-in-the-background">How to: Download a File in the Background</related>
</Docs>
<Members>
<Member MemberName=".ctor">
<MemberSignature Language="C#" Value="public BackgroundWorker ();" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig specialname rtspecialname instance void .ctor() cil managed" />
<MemberSignature Language="DocId" Value="M:System.ComponentModel.BackgroundWorker.#ctor" />
<MemberSignature Language="VB.NET" Value="Public Sub New ()" />
<MemberSignature Language="C++ CLI" Value="public:
 BackgroundWorker();" />
<MemberType>Constructor</MemberType>
<AssemblyInfo>
<AssemblyName>System.ComponentModel.EventBasedAsync</AssemblyName>
<AssemblyVersion>4.0.10.0</AssemblyVersion>
<AssemblyVersion>4.1.0.0</AssemblyVersion>
<AssemblyVersion>4.1.1.0</AssemblyVersion>
<AssemblyVersion>4.1.2.0</AssemblyVersion>
<AssemblyVersion>5.0.0.0</AssemblyVersion>
<AssemblyVersion>6.0.0.0</AssemblyVersion>
<AssemblyVersion>7.0.0.0</AssemblyVersion>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
<AssemblyVersion>9.0.0.0</AssemblyVersion>
<AssemblyVersion>10.0.0.0</AssemblyVersion>
<AssemblyVersion>11.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.0.5.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>netstandard</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.1.0.0</AssemblyVersion>
</AssemblyInfo>
<Parameters />
<Docs>
<summary>Initializes a new instance of the <see cref="T:System.ComponentModel.BackgroundWorker" /> class.</summary>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
This constructor initializes a <xref:System.ComponentModel.BackgroundWorker>.
]]></format>
</remarks>
<related type="Article" href="/dotnet/framework/winforms/controls/how-to-run-an-operation-in-the-background">How to: Run an Operation in the Background</related>
<related type="Article" href="/dotnet/framework/winforms/controls/how-to-download-a-file-in-the-background">How to: Download a File in the Background</related>
</Docs>
</Member>
<Member MemberName="CancelAsync">
<MemberSignature Language="C#" Value="public void CancelAsync ();" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig instance void CancelAsync() cil managed" />
<MemberSignature Language="DocId" Value="M:System.ComponentModel.BackgroundWorker.CancelAsync" />
<MemberSignature Language="VB.NET" Value="Public Sub CancelAsync ()" />
<MemberSignature Language="F#" Value="member this.CancelAsync : unit -> unit" Usage="backgroundWorker.CancelAsync " />
<MemberSignature Language="C++ CLI" Value="public:
 void CancelAsync();" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>System.ComponentModel.EventBasedAsync</AssemblyName>
<AssemblyVersion>4.0.10.0</AssemblyVersion>
<AssemblyVersion>4.1.0.0</AssemblyVersion>
<AssemblyVersion>4.1.1.0</AssemblyVersion>
<AssemblyVersion>4.1.2.0</AssemblyVersion>
<AssemblyVersion>5.0.0.0</AssemblyVersion>
<AssemblyVersion>6.0.0.0</AssemblyVersion>
<AssemblyVersion>7.0.0.0</AssemblyVersion>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
<AssemblyVersion>9.0.0.0</AssemblyVersion>
<AssemblyVersion>10.0.0.0</AssemblyVersion>
<AssemblyVersion>11.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.0.5.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>netstandard</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.1.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Void</ReturnType>
</ReturnValue>
<Parameters />
<Docs>
<summary>Requests cancellation of a pending background operation.</summary>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
<xref:System.ComponentModel.BackgroundWorker.CancelAsync*> submits a request to terminate the pending background operation and sets the <xref:System.ComponentModel.BackgroundWorker.CancellationPending> property to `true`.
When you call <xref:System.ComponentModel.BackgroundWorker.CancelAsync*>, your worker method has an opportunity to stop its execution and exit. The worker code should periodically check the <xref:System.ComponentModel.BackgroundWorker.CancellationPending> property to see if it has been set to `true`.
> [!CAUTION]
> Be aware that your code in the <xref:System.ComponentModel.BackgroundWorker.DoWork> event handler may finish its work as a cancellation request is being made, and your polling loop may miss <xref:System.ComponentModel.BackgroundWorker.CancellationPending*> being set to `true`. In this case, the <xref:System.ComponentModel.AsyncCompletedEventArgs.Cancelled*> flag of <xref:System.ComponentModel.RunWorkerCompletedEventArgs?displayProperty=nameWithType> in your <xref:System.ComponentModel.BackgroundWorker.RunWorkerCompleted> event handler will not be set to `true`, even though a cancellation request was made. This situation is called a *race condition* and is a common concern in multithreaded programming. For more information about multithreading design issues, see [Managed Threading Best Practices](/dotnet/standard/threading/managed-threading-best-practices).
## Examples
The following code example demonstrates the use of the <xref:System.ComponentModel.BackgroundWorker.CancelAsync*> method to cancel an asynchronous ("background") operation. This code example is part of a larger example provided for the <xref:System.ComponentModel.BackgroundWorker> class.
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_Winforms/System.ComponentModel.BackgroundWorker/CPP/fibonacciform.cpp" id="Snippet4":::
:::code language="csharp" source="~/snippets/csharp/System.ComponentModel/BackgroundWorker/Overview/fibonacciform.cs" id="Snippet4":::
:::code language="vb" source="~/snippets/visualbasic/System.ComponentModel/BackgroundWorker/Overview/fibonacciform.vb" id="Snippet4":::
]]></format>
</remarks>
<exception cref="T:System.InvalidOperationException">
<see cref="P:System.ComponentModel.BackgroundWorker.WorkerSupportsCancellation" /> is <see langword="false" />.</exception>
<related type="Article" href="/dotnet/framework/winforms/controls/how-to-run-an-operation-in-the-background">How to: Run an Operation in the Background</related>
<related type="Article" href="/dotnet/framework/winforms/controls/how-to-download-a-file-in-the-background">How to: Download a File in the Background</related>
</Docs>
</Member>
<Member MemberName="CancellationPending">
<MemberSignature Language="C#" Value="public bool CancellationPending { get; }" />
<MemberSignature Language="ILAsm" Value=".property instance bool CancellationPending" />
<MemberSignature Language="DocId" Value="P:System.ComponentModel.BackgroundWorker.CancellationPending" />
<MemberSignature Language="VB.NET" Value="Public ReadOnly Property CancellationPending As Boolean" />
<MemberSignature Language="F#" Value="member this.CancellationPending : bool" Usage="System.ComponentModel.BackgroundWorker.CancellationPending" />
<MemberSignature Language="C++ CLI" Value="public:
 property bool CancellationPending { bool get(); };" />
<MemberType>Property</MemberType>
<AssemblyInfo>
<AssemblyName>System.ComponentModel.EventBasedAsync</AssemblyName>
<AssemblyVersion>4.0.10.0</AssemblyVersion>
<AssemblyVersion>4.1.0.0</AssemblyVersion>
<AssemblyVersion>4.1.1.0</AssemblyVersion>
<AssemblyVersion>4.1.2.0</AssemblyVersion>
<AssemblyVersion>5.0.0.0</AssemblyVersion>
<AssemblyVersion>6.0.0.0</AssemblyVersion>
<AssemblyVersion>7.0.0.0</AssemblyVersion>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
<AssemblyVersion>9.0.0.0</AssemblyVersion>
<AssemblyVersion>10.0.0.0</AssemblyVersion>
<AssemblyVersion>11.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.0.5.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>netstandard</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.1.0.0</AssemblyVersion>
</AssemblyInfo>
<Attributes>
<Attribute FrameworkAlternate="netframework-2.0;netframework-3.0;netframework-3.5;netframework-4.0;netframework-4.5;netframework-4.5.1;netframework-4.5.2;netframework-4.6;netframework-4.6.1;netframework-4.6.2;netframework-4.7;netframework-4.7.1;netframework-4.7.2;netframework-4.8;netframework-4.8.1;netstandard-2.0;netstandard-2.1">
<AttributeName Language="C#">[System.ComponentModel.Browsable(false)]</AttributeName>
<AttributeName Language="F#">[<System.ComponentModel.Browsable(false)>]</AttributeName>
</Attribute>
<Attribute FrameworkAlternate="netframework-4.0">
<AttributeName Language="C#">[get: System.Runtime.TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]</AttributeName>
<AttributeName Language="F#">[<get: System.Runtime.TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")>]</AttributeName>
</Attribute>
</Attributes>
<ReturnValue>
<ReturnType>System.Boolean</ReturnType>
</ReturnValue>
<Docs>
<summary>Gets a value indicating whether the application has requested cancellation of a background operation.</summary>
<value>
<see langword="true" /> if the application has requested cancellation of a background operation; otherwise, <see langword="false" />. The default is <see langword="false" />.</value>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
If <xref:System.ComponentModel.BackgroundWorker.CancellationPending*> is `true`, then the <xref:System.ComponentModel.BackgroundWorker.CancelAsync*> method has been called on the <xref:System.ComponentModel.BackgroundWorker>.
This property is meant for use by the worker thread, which should periodically check <xref:System.ComponentModel.BackgroundWorker.CancellationPending*> and abort the background operation when it is set to `true`.
## Examples
The following code example demonstrates the use of the <xref:System.ComponentModel.BackgroundWorker.CancellationPending> property to query a <xref:System.ComponentModel.BackgroundWorker> about its cancellation state. This code example is part of a larger example provided for the <xref:System.ComponentModel.BackgroundWorker> class.
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_Winforms/System.ComponentModel.BackgroundWorker/CPP/fibonacciform.cpp" id="Snippet8":::
:::code language="csharp" source="~/snippets/csharp/System.ComponentModel/BackgroundWorker/Overview/fibonacciform.cs" id="Snippet8":::
:::code language="vb" source="~/snippets/visualbasic/System.ComponentModel/BackgroundWorker/Overview/fibonacciform.vb" id="Snippet8":::
]]></format>
</remarks>
<related type="Article" href="/dotnet/framework/winforms/controls/how-to-run-an-operation-in-the-background">How to: Run an Operation in the Background</related>
<related type="Article" href="/dotnet/framework/winforms/controls/how-to-download-a-file-in-the-background">How to: Download a File in the Background</related>
</Docs>
</Member>
<Member MemberName="Dispose">
<MemberSignature Language="C#" Value="public void Dispose ();" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig newslot virtual instance void Dispose() cil managed" />
<MemberSignature Language="DocId" Value="M:System.ComponentModel.BackgroundWorker.Dispose" />
<MemberSignature Language="VB.NET" Value="Public Sub Dispose ()" />
<MemberSignature Language="F#" Value="abstract member Dispose : unit -> unit
override this.Dispose : unit -> unit" Usage="backgroundWorker.Dispose " />
<MemberSignature Language="C++ CLI" Value="public:
 virtual void Dispose();" />
<MemberType>Method</MemberType>
<Implements>
<InterfaceMember>M:System.IDisposable.Dispose</InterfaceMember>
</Implements>
<AssemblyInfo>
<AssemblyName>System.ComponentModel.EventBasedAsync</AssemblyName>
<AssemblyVersion>4.0.10.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>netstandard</AssemblyName>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Void</ReturnType>
</ReturnValue>
<Parameters />
<Docs>
<summary>Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.</summary>
<remarks>To be added.</remarks>
</Docs>
</Member>
<Member MemberName="Dispose">
<MemberSignature Language="C#" Value="protected virtual void Dispose (bool disposing);" FrameworkAlternate="dotnet-uwp-10.0;netcore-1.0;netcore-1.1" />
<MemberSignature Language="ILAsm" Value=".method familyhidebysig newslot virtual instance void Dispose(bool disposing) cil managed" FrameworkAlternate="dotnet-uwp-10.0;netcore-1.0;netcore-1.1" />
<MemberSignature Language="DocId" Value="M:System.ComponentModel.BackgroundWorker.Dispose(System.Boolean)" />
<MemberSignature Language="VB.NET" Value="Protected Overridable Sub Dispose (disposing As Boolean)" FrameworkAlternate="dotnet-uwp-10.0;netcore-1.0;netcore-1.1" />
<MemberSignature Language="F#" Value="abstract member Dispose : bool -> unit
override this.Dispose : bool -> unit" Usage="backgroundWorker.Dispose disposing" FrameworkAlternate="dotnet-uwp-10.0;netcore-1.0;netcore-1.1" />
<MemberSignature Language="C++ CLI" Value="protected:
 virtual void Dispose(bool disposing);" FrameworkAlternate="dotnet-uwp-10.0;netcore-1.0;netcore-1.1" />
<MemberSignature Language="C#" Value="protected override void Dispose (bool disposing);" FrameworkAlternate="net-10.0;net-11.0;net-5.0;net-6.0;net-7.0;net-8.0;net-9.0;netcore-3.0;netcore-3.1;netstandard-2.1" />
<MemberSignature Language="ILAsm" Value=".method familyhidebysig virtual instance void Dispose(bool disposing) cil managed" FrameworkAlternate="net-10.0;net-11.0;net-5.0;net-6.0;net-7.0;net-8.0;net-9.0;netcore-3.0;netcore-3.1;netstandard-2.1" />
<MemberSignature Language="VB.NET" Value="Protected Overrides Sub Dispose (disposing As Boolean)" FrameworkAlternate="net-10.0;net-11.0;net-5.0;net-6.0;net-7.0;net-8.0;net-9.0;netcore-3.0;netcore-3.1;netstandard-2.1" />
<MemberSignature Language="F#" Value="override this.Dispose : bool -> unit" Usage="backgroundWorker.Dispose disposing" FrameworkAlternate="net-10.0;net-11.0;net-5.0;net-6.0;net-7.0;net-8.0;net-9.0;netcore-3.0;netcore-3.1;netstandard-2.1" />
<MemberSignature Language="C++ CLI" Value="protected:
 override void Dispose(bool disposing);" FrameworkAlternate="net-10.0;net-11.0;net-5.0;net-6.0;net-7.0;net-8.0;net-9.0;netcore-3.0;netcore-3.1;netstandard-2.1" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>System.ComponentModel.EventBasedAsync</AssemblyName>
<AssemblyVersion>4.0.10.0</AssemblyVersion>
<AssemblyVersion>4.1.1.0</AssemblyVersion>
<AssemblyVersion>4.1.2.0</AssemblyVersion>
<AssemblyVersion>5.0.0.0</AssemblyVersion>
<AssemblyVersion>6.0.0.0</AssemblyVersion>
<AssemblyVersion>7.0.0.0</AssemblyVersion>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
<AssemblyVersion>9.0.0.0</AssemblyVersion>
<AssemblyVersion>10.0.0.0</AssemblyVersion>
<AssemblyVersion>11.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>netstandard</AssemblyName>
<AssemblyVersion>2.1.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Void</ReturnType>
</ReturnValue>
<Parameters>
<Parameter Name="disposing" Type="System.Boolean" Index="0" FrameworkAlternate="dotnet-uwp-10.0;net-10.0;net-11.0;net-5.0;net-6.0;net-7.0;net-8.0;net-9.0;netcore-1.0;netcore-1.1;netcore-3.0;netcore-3.1;netstandard-2.1" />
</Parameters>
<Docs>
<param name="disposing">This method does not do anything.</param>
<summary>This method does not do anything.</summary>
<remarks>To be added.</remarks>
</Docs>
</Member>
<Member MemberName="DoWork">
<MemberSignature Language="C#" Value="public event System.ComponentModel.DoWorkEventHandler DoWork;" FrameworkAlternate="dotnet-uwp-10.0;netcore-1.0;netcore-1.1;netcore-2.0;netcore-2.1;netcore-2.2;netcore-3.0;netcore-3.1;netframework-2.0;netframework-3.0;netframework-3.5;netframework-4.0;netframework-4.5;netframework-4.5.1;netframework-4.5.2;netframework-4.6;netframework-4.6.1;netframework-4.6.2;netframework-4.7;netframework-4.7.1;netframework-4.7.2;netframework-4.8;netframework-4.8.1;netstandard-2.0;netstandard-2.1" />
<MemberSignature Language="ILAsm" Value=".event class System.ComponentModel.DoWorkEventHandler DoWork" />
<MemberSignature Language="DocId" Value="E:System.ComponentModel.BackgroundWorker.DoWork" />
<MemberSignature Language="VB.NET" Value="Public Custom Event DoWork As DoWorkEventHandler " />
<MemberSignature Language="F#" Value="member this.DoWork : System.ComponentModel.DoWorkEventHandler " Usage="member this.DoWork : System.ComponentModel.DoWorkEventHandler " />
<MemberSignature Language="C++ CLI" Value="public:
 event System::ComponentModel::DoWorkEventHandler ^ DoWork;" />
<MemberSignature Language="C#" Value="public event System.ComponentModel.DoWorkEventHandler? DoWork;" FrameworkAlternate="net-10.0;net-11.0;net-5.0;net-6.0;net-7.0;net-8.0;net-9.0" />
<MemberType>Event</MemberType>
<AssemblyInfo>
<AssemblyName>System.ComponentModel.EventBasedAsync</AssemblyName>
<AssemblyVersion>4.0.10.0</AssemblyVersion>
<AssemblyVersion>4.1.0.0</AssemblyVersion>
<AssemblyVersion>4.1.1.0</AssemblyVersion>
<AssemblyVersion>4.1.2.0</AssemblyVersion>
<AssemblyVersion>5.0.0.0</AssemblyVersion>
<AssemblyVersion>6.0.0.0</AssemblyVersion>
<AssemblyVersion>7.0.0.0</AssemblyVersion>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
<AssemblyVersion>9.0.0.0</AssemblyVersion>
<AssemblyVersion>10.0.0.0</AssemblyVersion>
<AssemblyVersion>11.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.0.5.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>netstandard</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.1.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.ComponentModel.DoWorkEventHandler</ReturnType>
</ReturnValue>
<Docs>
<summary>Occurs when <see cref="M:System.ComponentModel.BackgroundWorker.RunWorkerAsync" /> is called.</summary>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
This event is raised when you call the <xref:System.ComponentModel.BackgroundWorker.RunWorkerAsync*> method. This is where you start the operation that performs the potentially time-consuming work.
Your code in the <xref:System.ComponentModel.BackgroundWorker.DoWork> event handler should periodically check the <xref:System.ComponentModel.BackgroundWorker.CancellationPending> property value and abort the operation if it is `true`. When this occurs, you can set the <xref:System.ComponentModel.CancelEventArgs.Cancel*> flag of <xref:System.ComponentModel.DoWorkEventArgs?displayProperty=nameWithType> to `true`, and the <xref:System.ComponentModel.AsyncCompletedEventArgs.Cancelled*> flag of <xref:System.ComponentModel.RunWorkerCompletedEventArgs?displayProperty=nameWithType> in your <xref:System.ComponentModel.BackgroundWorker.RunWorkerCompleted> event handler will be set to `true`.
> [!CAUTION]
> Be aware that your code in the <xref:System.ComponentModel.BackgroundWorker.DoWork> event handler may finish its work as a cancellation request is being made, and your polling loop may miss <xref:System.ComponentModel.BackgroundWorker.CancellationPending*> being set to `true`. In this case, the <xref:System.ComponentModel.AsyncCompletedEventArgs.Cancelled*> flag of <xref:System.ComponentModel.RunWorkerCompletedEventArgs?displayProperty=nameWithType> in your <xref:System.ComponentModel.BackgroundWorker.RunWorkerCompleted> event handler will not be set to `true`, even though a cancellation request was made. This situation is called a *race condition* and is a common concern in multithreaded programming. For more information about multithreading design issues, see [Managed Threading Best Practices](/dotnet/standard/threading/managed-threading-best-practices).
If your operation produces a result, you can assign the result to the <xref:System.ComponentModel.DoWorkEventArgs.Result?displayProperty=nameWithType> property. This will be available to the <xref:System.ComponentModel.BackgroundWorker.RunWorkerCompleted> event handler in the <xref:System.ComponentModel.RunWorkerCompletedEventArgs.Result?displayProperty=nameWithType> property.
If the operation raises an exception that your code does not handle, the <xref:System.ComponentModel.BackgroundWorker> catches the exception and passes it into the <xref:System.ComponentModel.BackgroundWorker.RunWorkerCompleted> event handler, where it is exposed as the <xref:System.ComponentModel.AsyncCompletedEventArgs.Error> property of <xref:System.ComponentModel.RunWorkerCompletedEventArgs?displayProperty=nameWithType>. If you are running under the Visual Studio debugger, the debugger will break at the point in the <xref:System.ComponentModel.BackgroundWorker.DoWork> event handler where the unhandled exception was raised. If you have more than one <xref:System.ComponentModel.BackgroundWorker>, you should not reference any of them directly, as this would couple your <xref:System.ComponentModel.BackgroundWorker.DoWork> event handler to a specific instance of <xref:System.ComponentModel.BackgroundWorker>. Instead, you should access your <xref:System.ComponentModel.BackgroundWorker> by casting the `sender` parameter in your <xref:System.ComponentModel.BackgroundWorker.DoWork> event handler.
You must be careful not to manipulate any user-interface objects in your <xref:System.ComponentModel.BackgroundWorker.DoWork> event handler. Instead, communicate to the user interface through the <xref:System.ComponentModel.BackgroundWorker> events.
For more information about how to handle events, see [Handling and Raising Events](/dotnet/standard/events/).
## Examples
The following code example demonstrates the use of the <xref:System.ComponentModel.BackgroundWorker.DoWork> event to start an asynchronous operation. This code example is part of a larger example provided for the <xref:System.ComponentModel.BackgroundWorker> class.
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_Winforms/System.ComponentModel.BackgroundWorker/CPP/fibonacciform.cpp" id="Snippet5":::
:::code language="csharp" source="~/snippets/csharp/System.ComponentModel/BackgroundWorker/Overview/fibonacciform.cs" id="Snippet5":::
:::code language="vb" source="~/snippets/visualbasic/System.ComponentModel/BackgroundWorker/Overview/fibonacciform.vb" id="Snippet5":::
]]></format>
</remarks>
<related type="Article" href="/dotnet/framework/winforms/controls/how-to-run-an-operation-in-the-background">How to: Run an Operation in the Background</related>
<related type="Article" href="/dotnet/standard/threading/managed-threading-best-practices">Managed Threading Best Practices</related>
<related type="Article" href="/dotnet/framework/winforms/controls/how-to-download-a-file-in-the-background">How to: Download a File in the Background</related>
</Docs>
</Member>
<Member MemberName="IsBusy">
<MemberSignature Language="C#" Value="public bool IsBusy { get; }" />
<MemberSignature Language="ILAsm" Value=".property instance bool IsBusy" />
<MemberSignature Language="DocId" Value="P:System.ComponentModel.BackgroundWorker.IsBusy" />
<MemberSignature Language="VB.NET" Value="Public ReadOnly Property IsBusy As Boolean" />
<MemberSignature Language="F#" Value="member this.IsBusy : bool" Usage="System.ComponentModel.BackgroundWorker.IsBusy" />
<MemberSignature Language="C++ CLI" Value="public:
 property bool IsBusy { bool get(); };" />
<MemberType>Property</MemberType>
<AssemblyInfo>
<AssemblyName>System.ComponentModel.EventBasedAsync</AssemblyName>
<AssemblyVersion>4.0.10.0</AssemblyVersion>
<AssemblyVersion>4.1.0.0</AssemblyVersion>
<AssemblyVersion>4.1.1.0</AssemblyVersion>
<AssemblyVersion>4.1.2.0</AssemblyVersion>
<AssemblyVersion>5.0.0.0</AssemblyVersion>
<AssemblyVersion>6.0.0.0</AssemblyVersion>
<AssemblyVersion>7.0.0.0</AssemblyVersion>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
<AssemblyVersion>9.0.0.0</AssemblyVersion>
<AssemblyVersion>10.0.0.0</AssemblyVersion>
<AssemblyVersion>11.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.0.5.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>netstandard</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.1.0.0</AssemblyVersion>
</AssemblyInfo>
<Attributes>
<Attribute FrameworkAlternate="netframework-2.0;netframework-3.0;netframework-3.5;netframework-4.0;netframework-4.5;netframework-4.5.1;netframework-4.5.2;netframework-4.6;netframework-4.6.1;netframework-4.6.2;netframework-4.7;netframework-4.7.1;netframework-4.7.2;netframework-4.8;netframework-4.8.1;netstandard-2.0;netstandard-2.1">
<AttributeName Language="C#">[System.ComponentModel.Browsable(false)]</AttributeName>
<AttributeName Language="F#">[<System.ComponentModel.Browsable(false)>]</AttributeName>
</Attribute>
<Attribute FrameworkAlternate="netframework-4.0">
<AttributeName Language="C#">[get: System.Runtime.TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]</AttributeName>
<AttributeName Language="F#">[<get: System.Runtime.TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")>]</AttributeName>
</Attribute>
</Attributes>
<ReturnValue>
<ReturnType>System.Boolean</ReturnType>
</ReturnValue>
<Docs>
<summary>Gets a value indicating whether the <see cref="T:System.ComponentModel.BackgroundWorker" /> is running an asynchronous operation.</summary>
<value>
<see langword="true" />, if the <see cref="T:System.ComponentModel.BackgroundWorker" /> is running an asynchronous operation; otherwise, <see langword="false" />.</value>
<remarks>
<format type="text/markdown"><.
:::code language="csharp" source="~/snippets/csharp/System.ComponentModel/BackgroundWorker/IsBusy/Form1.cs" id="Snippet2":::
:::code language="vb" source="~/snippets/visualbasic/System.ComponentModel/BackgroundWorker/IsBusy/Form1.vb" id="Snippet2":::
]]></format>
</remarks>
<altmember cref="E:System.ComponentModel.BackgroundWorker.RunWorkerCompleted" />
<altmember cref="T:System.EventArgs" />
<altmember cref="Overload:System.ComponentModel.BackgroundWorker.RunWorkerAsync" />
<related type="Article" href="/dotnet/framework/winforms/controls/how-to-run-an-operation-in-the-background">How to: Run an Operation in the Background</related>
<related type="Article" href="/dotnet/framework/winforms/controls/how-to-download-a-file-in-the-background">How to: Download a File in the Background</related>
</Docs>
</Member>
<Member MemberName="OnDoWork">
<MemberSignature Language="C#" Value="protected virtual void OnDoWork (System.ComponentModel.DoWorkEventArgs e);" />
<MemberSignature Language="ILAsm" Value=".method familyhidebysig newslot virtual instance void OnDoWork(class System.ComponentModel.DoWorkEventArgs e) cil managed" />
<MemberSignature Language="DocId" Value="M:System.ComponentModel.BackgroundWorker.OnDoWork(System.ComponentModel.DoWorkEventArgs)" />
<MemberSignature Language="VB.NET" Value="Protected Overridable Sub OnDoWork (e As DoWorkEventArgs)" />
<MemberSignature Language="F#" Value="abstract member OnDoWork : System.ComponentModel.DoWorkEventArgs -> unit
override this.OnDoWork : System.ComponentModel.DoWorkEventArgs -> unit" Usage="backgroundWorker.OnDoWork e" />
<MemberSignature Language="C++ CLI" Value="protected:
 virtual void OnDoWork(System::ComponentModel::DoWorkEventArgs ^ e);" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>System.ComponentModel.EventBasedAsync</AssemblyName>
<AssemblyVersion>4.0.10.0</AssemblyVersion>
<AssemblyVersion>4.1.0.0</AssemblyVersion>
<AssemblyVersion>4.1.1.0</AssemblyVersion>
<AssemblyVersion>4.1.2.0</AssemblyVersion>
<AssemblyVersion>5.0.0.0</AssemblyVersion>
<AssemblyVersion>6.0.0.0</AssemblyVersion>
<AssemblyVersion>7.0.0.0</AssemblyVersion>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
<AssemblyVersion>9.0.0.0</AssemblyVersion>
<AssemblyVersion>10.0.0.0</AssemblyVersion>
<AssemblyVersion>11.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.0.5.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>netstandard</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.1.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Void</ReturnType>
</ReturnValue>
<Parameters>
<Parameter Name="e" Type="System.ComponentModel.DoWorkEventArgs" />
</Parameters>
<Docs>
<param name="e">An <see cref="T:System.EventArgs" /> that contains the event data.</param>
<summary>Raises the <see cref="E:System.ComponentModel.BackgroundWorker.DoWork" /> event.</summary>
<remarks>To be added.</remarks>
</Docs>
</Member>
<Member MemberName="OnProgressChanged">
<MemberSignature Language="C#" Value="protected virtual void OnProgressChanged (System.ComponentModel.ProgressChangedEventArgs e);" />
<MemberSignature Language="ILAsm" Value=".method familyhidebysig newslot virtual instance void OnProgressChanged(class System.ComponentModel.ProgressChangedEventArgs e) cil managed" />
<MemberSignature Language="DocId" Value="M:System.ComponentModel.BackgroundWorker.OnProgressChanged(System.ComponentModel.ProgressChangedEventArgs)" />
<MemberSignature Language="VB.NET" Value="Protected Overridable Sub OnProgressChanged (e As ProgressChangedEventArgs)" />
<MemberSignature Language="F#" Value="abstract member OnProgressChanged : System.ComponentModel.ProgressChangedEventArgs -> unit
override this.OnProgressChanged : System.ComponentModel.ProgressChangedEventArgs -> unit" Usage="backgroundWorker.OnProgressChanged e" />
<MemberSignature Language="C++ CLI" Value="protected:
 virtual void OnProgressChanged(System::ComponentModel::ProgressChangedEventArgs ^ e);" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>System.ComponentModel.EventBasedAsync</AssemblyName>
<AssemblyVersion>4.0.10.0</AssemblyVersion>
<AssemblyVersion>4.1.0.0</AssemblyVersion>
<AssemblyVersion>4.1.1.0</AssemblyVersion>
<AssemblyVersion>4.1.2.0</AssemblyVersion>
<AssemblyVersion>5.0.0.0</AssemblyVersion>
<AssemblyVersion>6.0.0.0</AssemblyVersion>
<AssemblyVersion>7.0.0.0</AssemblyVersion>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
<AssemblyVersion>9.0.0.0</AssemblyVersion>
<AssemblyVersion>10.0.0.0</AssemblyVersion>
<AssemblyVersion>11.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.0.5.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>netstandard</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.1.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Void</ReturnType>
</ReturnValue>
<Parameters>
<Parameter Name="e" Type="System.ComponentModel.ProgressChangedEventArgs" />
</Parameters>
<Docs>
<param name="e">An <see cref="T:System.EventArgs" /> that contains the event data.</param>
<summary>Raises the <see cref="E:System.ComponentModel.BackgroundWorker.ProgressChanged" /> event.</summary>
<remarks>
<format type="text/markdown"><.
The <xref:System.ComponentModel.BackgroundWorker.OnProgressChanged*> method also allows derived classes to handle the event without attaching a delegate. This is the preferred technique for handling the event in a derived class.
## Examples
The following code example demonstrates the use of the <xref:System.ComponentModel.BackgroundWorker.OnProgressChanged*> method to report the progress of an asynchronous operation. This code example is part of a larger example provided for the <xref:System.ComponentModel.AsyncOperationManager> class.
:::code language="csharp" source="~/snippets/csharp/System.ComponentModel/AsyncCompletedEventArgs/Overview/primenumbercalculatormain.cs" id="Snippet24":::
:::code language="vb" source="~/snippets/visualbasic/System.ComponentModel/AsyncCompletedEventArgs/Overview/primenumbercalculatormain.vb" id="Snippet24":::
]]></format>
</remarks>
<block subset="none" type="overrides">
<para>When overriding <see cref="M:System.ComponentModel.BackgroundWorker.OnProgressChanged(System.ComponentModel.ProgressChangedEventArgs)" /> in a derived class, be sure to call the base class's <see cref="M:System.ComponentModel.BackgroundWorker.OnProgressChanged(System.ComponentModel.ProgressChangedEventArgs)" /> method so that registered delegates receive the event.</para>
</block>
<altmember cref="E:System.ComponentModel.BackgroundWorker.ProgressChanged" />
<related type="Article" href="/dotnet/framework/winforms/controls/how-to-run-an-operation-in-the-background">How to: Run an Operation in the Background</related>
<related type="Article" href="/dotnet/framework/winforms/controls/how-to-download-a-file-in-the-background">How to: Download a File in the Background</related>
</Docs>
</Member>
<Member MemberName="OnRunWorkerCompleted">
<MemberSignature Language="C#" Value="protected virtual void OnRunWorkerCompleted (System.ComponentModel.RunWorkerCompletedEventArgs e);" />
<MemberSignature Language="ILAsm" Value=".method familyhidebysig newslot virtual instance void OnRunWorkerCompleted(class System.ComponentModel.RunWorkerCompletedEventArgs e) cil managed" />
<MemberSignature Language="DocId" Value="M:System.ComponentModel.BackgroundWorker.OnRunWorkerCompleted(System.ComponentModel.RunWorkerCompletedEventArgs)" />
<MemberSignature Language="VB.NET" Value="Protected Overridable Sub OnRunWorkerCompleted (e As RunWorkerCompletedEventArgs)" />
<MemberSignature Language="F#" Value="abstract member OnRunWorkerCompleted : System.ComponentModel.RunWorkerCompletedEventArgs -> unit
override this.OnRunWorkerCompleted : System.ComponentModel.RunWorkerCompletedEventArgs -> unit" Usage="backgroundWorker.OnRunWorkerCompleted e" />
<MemberSignature Language="C++ CLI" Value="protected:
 virtual void OnRunWorkerCompleted(System::ComponentModel::RunWorkerCompletedEventArgs ^ e);" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>System.ComponentModel.EventBasedAsync</AssemblyName>
<AssemblyVersion>4.0.10.0</AssemblyVersion>
<AssemblyVersion>4.1.0.0</AssemblyVersion>
<AssemblyVersion>4.1.1.0</AssemblyVersion>
<AssemblyVersion>4.1.2.0</AssemblyVersion>
<AssemblyVersion>5.0.0.0</AssemblyVersion>
<AssemblyVersion>6.0.0.0</AssemblyVersion>
<AssemblyVersion>7.0.0.0</AssemblyVersion>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
<AssemblyVersion>9.0.0.0</AssemblyVersion>
<AssemblyVersion>10.0.0.0</AssemblyVersion>
<AssemblyVersion>11.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.0.5.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>netstandard</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.1.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Void</ReturnType>
</ReturnValue>
<Parameters>
<Parameter Name="e" Type="System.ComponentModel.RunWorkerCompletedEventArgs" />
</Parameters>
<Docs>
<param name="e">An <see cref="T:System.EventArgs" /> that contains the event data.</param>
<summary>Raises the <see cref="E:System.ComponentModel.BackgroundWorker.RunWorkerCompleted" /> event.</summary>
<remarks>
<format type="text/markdown"><.
The <xref:System.ComponentModel.BackgroundWorker.OnRunWorkerCompleted*> method also allows derived classes to handle the event without attaching a delegate. This is the preferred technique for handling the event in a derived class.
]]></format>
</remarks>
<block subset="none" type="overrides">
<para>When overriding <see cref="M:System.ComponentModel.BackgroundWorker.OnRunWorkerCompleted(System.ComponentModel.RunWorkerCompletedEventArgs)" /> in a derived class, be sure to call the base class's <see cref="M:System.ComponentModel.BackgroundWorker.OnRunWorkerCompleted(System.ComponentModel.RunWorkerCompletedEventArgs)" /> method so that registered delegates receive the event.</para>
</block>
<altmember cref="E:System.ComponentModel.BackgroundWorker.RunWorkerCompleted" />
<related type="Article" href="/dotnet/framework/winforms/controls/how-to-run-an-operation-in-the-background">How to: Run an Operation in the Background</related>
<related type="Article" href="/dotnet/framework/winforms/controls/how-to-download-a-file-in-the-background">How to: Download a File in the Background</related>
</Docs>
</Member>
<Member MemberName="ProgressChanged">
<MemberSignature Language="C#" Value="public event System.ComponentModel.ProgressChangedEventHandler ProgressChanged;" FrameworkAlternate="dotnet-uwp-10.0;netcore-1.0;netcore-1.1;netcore-2.0;netcore-2.1;netcore-2.2;netcore-3.0;netcore-3.1;netframework-2.0;netframework-3.0;netframework-3.5;netframework-4.0;netframework-4.5;netframework-4.5.1;netframework-4.5.2;netframework-4.6;netframework-4.6.1;netframework-4.6.2;netframework-4.7;netframework-4.7.1;netframework-4.7.2;netframework-4.8;netframework-4.8.1;netstandard-2.0;netstandard-2.1" />
<MemberSignature Language="ILAsm" Value=".event class System.ComponentModel.ProgressChangedEventHandler ProgressChanged" />
<MemberSignature Language="DocId" Value="E:System.ComponentModel.BackgroundWorker.ProgressChanged" />
<MemberSignature Language="VB.NET" Value="Public Custom Event ProgressChanged As ProgressChangedEventHandler " />
<MemberSignature Language="F#" Value="member this.ProgressChanged : System.ComponentModel.ProgressChangedEventHandler " Usage="member this.ProgressChanged : System.ComponentModel.ProgressChangedEventHandler " />
<MemberSignature Language="C++ CLI" Value="public:
 event System::ComponentModel::ProgressChangedEventHandler ^ ProgressChanged;" />
<MemberSignature Language="C#" Value="public event System.ComponentModel.ProgressChangedEventHandler? ProgressChanged;" FrameworkAlternate="net-10.0;net-11.0;net-5.0;net-6.0;net-7.0;net-8.0;net-9.0" />
<MemberType>Event</MemberType>
<AssemblyInfo>
<AssemblyName>System.ComponentModel.EventBasedAsync</AssemblyName>
<AssemblyVersion>4.0.10.0</AssemblyVersion>
<AssemblyVersion>4.1.0.0</AssemblyVersion>
<AssemblyVersion>4.1.1.0</AssemblyVersion>
<AssemblyVersion>4.1.2.0</AssemblyVersion>
<AssemblyVersion>5.0.0.0</AssemblyVersion>
<AssemblyVersion>6.0.0.0</AssemblyVersion>
<AssemblyVersion>7.0.0.0</AssemblyVersion>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
<AssemblyVersion>9.0.0.0</AssemblyVersion>
<AssemblyVersion>10.0.0.0</AssemblyVersion>
<AssemblyVersion>11.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.0.5.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>netstandard</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.1.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.ComponentModel.ProgressChangedEventHandler</ReturnType>
</ReturnValue>
<Docs>
<summary>Occurs when <see cref="M:System.ComponentModel.BackgroundWorker.ReportProgress(System.Int32)" /> is called.</summary>
<remarks>
<format type="text/markdown"><.
## Examples
The following code example demonstrates the use of the <xref:System.ComponentModel.BackgroundWorker.ProgressChanged> event to report the progress of an asynchronous operation to the user. This code example is part of a larger example provided for the <xref:System.ComponentModel.BackgroundWorker> class.
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_Winforms/System.ComponentModel.BackgroundWorker/CPP/fibonacciform.cpp" id="Snippet7":::
:::code language="csharp" source="~/snippets/csharp/System.ComponentModel/BackgroundWorker/Overview/fibonacciform.cs" id="Snippet7":::
:::code language="vb" source="~/snippets/visualbasic/System.ComponentModel/BackgroundWorker/Overview/fibonacciform.vb" id="Snippet7":::
]]></format>
</remarks>
<related type="Article" href="/dotnet/framework/winforms/controls/how-to-run-an-operation-in-the-background">How to: Run an Operation in the Background</related>
<related type="Article" href="/dotnet/framework/winforms/controls/how-to-download-a-file-in-the-background">How to: Download a File in the Background</related>
</Docs>
</Member>
<MemberGroup MemberName="ReportProgress">
<AssemblyInfo>
<AssemblyName>System.ComponentModel.EventBasedAsync</AssemblyName>
<AssemblyVersion>4.0.10.0</AssemblyVersion>
<AssemblyVersion>4.1.0.0</AssemblyVersion>
</AssemblyInfo>
<Docs>
<summary>Raises the <see cref="E:System.ComponentModel.BackgroundWorker.ProgressChanged" /> event.</summary>
</Docs>
</MemberGroup>
<Member MemberName="ReportProgress">
<MemberSignature Language="C#" Value="public void ReportProgress (int percentProgress);" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig instance void ReportProgress(int32 percentProgress) cil managed" />
<MemberSignature Language="DocId" Value="M:System.ComponentModel.BackgroundWorker.ReportProgress(System.Int32)" />
<MemberSignature Language="VB.NET" Value="Public Sub ReportProgress (percentProgress As Integer)" />
<MemberSignature Language="F#" Value="member this.ReportProgress : int -> unit" Usage="backgroundWorker.ReportProgress percentProgress" />
<MemberSignature Language="C++ CLI" Value="public:
 void ReportProgress(int percentProgress);" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>System.ComponentModel.EventBasedAsync</AssemblyName>
<AssemblyVersion>4.0.10.0</AssemblyVersion>
<AssemblyVersion>4.1.0.0</AssemblyVersion>
<AssemblyVersion>4.1.1.0</AssemblyVersion>
<AssemblyVersion>4.1.2.0</AssemblyVersion>
<AssemblyVersion>5.0.0.0</AssemblyVersion>
<AssemblyVersion>6.0.0.0</AssemblyVersion>
<AssemblyVersion>7.0.0.0</AssemblyVersion>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
<AssemblyVersion>9.0.0.0</AssemblyVersion>
<AssemblyVersion>10.0.0.0</AssemblyVersion>
<AssemblyVersion>11.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.0.5.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>netstandard</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.1.0.0</AssemblyVersion>
</AssemblyInfo>
<Attributes>
<Attribute FrameworkAlternate="netframework-4.0">
<AttributeName Language="C#">[System.Runtime.TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]</AttributeName>
<AttributeName Language="F#">[<System.Runtime.TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")>]</AttributeName>
</Attribute>
</Attributes>
<ReturnValue>
<ReturnType>System.Void</ReturnType>
</ReturnValue>
<Parameters>
<Parameter Name="percentProgress" Type="System.Int32" />
</Parameters>
<Docs>
<param name="percentProgress">The percentage, from 0 to 100, of the background operation that is complete.</param>
<summary>Raises the <see cref="E:System.ComponentModel.BackgroundWorker.ProgressChanged" /> event.</summary>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
If you need the background operation to report on its progress, you can call the <xref:System.ComponentModel.BackgroundWorker.ReportProgress*> method to raise the <xref:System.ComponentModel.BackgroundWorker.ProgressChanged> event. The <xref:System.ComponentModel.BackgroundWorker.WorkerReportsProgress> property value must be `true`, or <xref:System.ComponentModel.BackgroundWorker.ReportProgress*> will throw an <xref:System.InvalidOperationException>.
It is up to you to implement a meaningful way of measuring your background operation's progress as a percentage of the total task completed.
The call to the <xref:System.ComponentModel.BackgroundWorker.ReportProgress*> method is asynchronous and returns immediately. The <xref:System.ComponentModel.BackgroundWorker.ProgressChanged> event handler executes on the thread that created the <xref:System.ComponentModel.BackgroundWorker>.
## Examples
The following code example demonstrates the use of the <xref:System.ComponentModel.BackgroundWorker.ReportProgress*> method to report the progress of an asynchronous operation to the user. This code example is part of a larger example provided for the <xref:System.ComponentModel.BackgroundWorker> class.
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_Winforms/System.ComponentModel.BackgroundWorker/CPP/fibonacciform.cpp" id="Snippet8":::
:::code language="csharp" source="~/snippets/csharp/System.ComponentModel/BackgroundWorker/Overview/fibonacciform.cs" id="Snippet8":::
:::code language="vb" source="~/snippets/visualbasic/System.ComponentModel/BackgroundWorker/Overview/fibonacciform.vb" id="Snippet8":::
]]></format>
</remarks>
<exception cref="T:System.InvalidOperationException">The <see cref="P:System.ComponentModel.BackgroundWorker.WorkerReportsProgress" /> property is set to <see langword="false" />.</exception>
<related type="Article" href="/dotnet/framework/winforms/controls/how-to-run-an-operation-in-the-background">How to: Run an Operation in the Background</related>
<related type="Article" href="/dotnet/framework/winforms/controls/how-to-download-a-file-in-the-background">How to: Download a File in the Background</related>
</Docs>
</Member>
<Member MemberName="ReportProgress">
<MemberSignature Language="C#" Value="public void ReportProgress (int percentProgress, object userState);" FrameworkAlternate="dotnet-uwp-10.0;netcore-1.0;netcore-1.1;netcore-2.0;netcore-2.1;netcore-2.2;netcore-3.0;netcore-3.1;netframework-2.0;netframework-3.0;netframework-3.5;netframework-4.0;netframework-4.5;netframework-4.5.1;netframework-4.5.2;netframework-4.6;netframework-4.6.1;netframework-4.6.2;netframework-4.7;netframework-4.7.1;netframework-4.7.2;netframework-4.8;netframework-4.8.1;netstandard-2.0;netstandard-2.1" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig instance void ReportProgress(int32 percentProgress, object userState) cil managed" />
<MemberSignature Language="DocId" Value="M:System.ComponentModel.BackgroundWorker.ReportProgress(System.Int32,System.Object)" />
<MemberSignature Language="VB.NET" Value="Public Sub ReportProgress (percentProgress As Integer, userState As Object)" />
<MemberSignature Language="F#" Value="member this.ReportProgress : int * obj -> unit" Usage="backgroundWorker.ReportProgress (percentProgress, userState)" />
<MemberSignature Language="C++ CLI" Value="public:
 void ReportProgress(int percentProgress, System::Object ^ userState);" />
<MemberSignature Language="C#" Value="public void ReportProgress (int percentProgress, object? userState);" FrameworkAlternate="net-10.0;net-11.0;net-5.0;net-6.0;net-7.0;net-8.0;net-9.0" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>System.ComponentModel.EventBasedAsync</AssemblyName>
<AssemblyVersion>4.0.10.0</AssemblyVersion>
<AssemblyVersion>4.1.0.0</AssemblyVersion>
<AssemblyVersion>4.1.1.0</AssemblyVersion>
<AssemblyVersion>4.1.2.0</AssemblyVersion>
<AssemblyVersion>5.0.0.0</AssemblyVersion>
<AssemblyVersion>6.0.0.0</AssemblyVersion>
<AssemblyVersion>7.0.0.0</AssemblyVersion>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
<AssemblyVersion>9.0.0.0</AssemblyVersion>
<AssemblyVersion>10.0.0.0</AssemblyVersion>
<AssemblyVersion>11.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.0.5.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>netstandard</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.1.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Void</ReturnType>
</ReturnValue>
<Parameters>
<Parameter Name="percentProgress" Type="System.Int32" />
<Parameter Name="userState" Type="System.Object" />
</Parameters>
<Docs>
<param name="percentProgress">The percentage, from 0 to 100, of the background operation that is complete.</param>
<param name="userState">A unique <see cref="T:System.Object" /> indicating the user state. Returned as the <see cref="P:System.ComponentModel.ProgressChangedEventArgs.UserState" /> property of the <see cref="T:System.ComponentModel.ProgressChangedEventArgs" />.</param>
<summary>Raises the <see cref="E:System.ComponentModel.BackgroundWorker.ProgressChanged" /> event.</summary>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
If you need the background operation to report on its progress, you can call the <xref:System.ComponentModel.BackgroundWorker.ReportProgress*> method to raise the <xref:System.ComponentModel.BackgroundWorker.ProgressChanged> event. The <xref:System.ComponentModel.BackgroundWorker.WorkerReportsProgress> property value must `true`, or <xref:System.ComponentModel.BackgroundWorker.ReportProgress*> will throw an <xref:System.InvalidOperationException>.
It is up to you to implement a meaningful way of measuring your background operation's progress as a percentage of the total task completed.
## Examples
The following code example demonstrates the use of the <xref:System.ComponentModel.BackgroundWorker.ReportProgress*> method to report the progress of an asynchronous operation to the user. This code example is part of a larger example provided for the <xref:System.Windows.Forms.ToolStripProgressBar> class.
:::code language="csharp" source="~/snippets/csharp/System.ComponentModel/BackgroundWorker/ReportProgress/form1.cs" id="Snippet10":::
:::code language="vb" source="~/snippets/visualbasic/System.ComponentModel/BackgroundWorker/ReportProgress/form1.vb" id="Snippet10":::
]]></format>
</remarks>
<exception cref="T:System.InvalidOperationException">The <see cref="P:System.ComponentModel.BackgroundWorker.WorkerReportsProgress" /> property is set to <see langword="false" />.</exception>
<related type="Article" href="/dotnet/framework/winforms/controls/how-to-run-an-operation-in-the-background">How to: Run an Operation in the Background</related>
<related type="Article" href="/dotnet/framework/winforms/controls/how-to-download-a-file-in-the-background">How to: Download a File in the Background</related>
</Docs>
</Member>
<MemberGroup MemberName="RunWorkerAsync">
<AssemblyInfo>
<AssemblyName>System.ComponentModel.EventBasedAsync</AssemblyName>
<AssemblyVersion>4.0.10.0</AssemblyVersion>
<AssemblyVersion>4.1.0.0</AssemblyVersion>
</AssemblyInfo>
<Docs>
<summary>Starts execution of a background operation.</summary>
</Docs>
</MemberGroup>
<Member MemberName="RunWorkerAsync">
<MemberSignature Language="C#" Value="public void RunWorkerAsync ();" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig instance void RunWorkerAsync() cil managed" />
<MemberSignature Language="DocId" Value="M:System.ComponentModel.BackgroundWorker.RunWorkerAsync" />
<MemberSignature Language="VB.NET" Value="Public Sub RunWorkerAsync ()" />
<MemberSignature Language="F#" Value="member this.RunWorkerAsync : unit -> unit" Usage="backgroundWorker.RunWorkerAsync " />
<MemberSignature Language="C++ CLI" Value="public:
 void RunWorkerAsync();" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>System.ComponentModel.EventBasedAsync</AssemblyName>
<AssemblyVersion>4.0.10.0</AssemblyVersion>
<AssemblyVersion>4.1.0.0</AssemblyVersion>
<AssemblyVersion>4.1.1.0</AssemblyVersion>
<AssemblyVersion>4.1.2.0</AssemblyVersion>
<AssemblyVersion>5.0.0.0</AssemblyVersion>
<AssemblyVersion>6.0.0.0</AssemblyVersion>
<AssemblyVersion>7.0.0.0</AssemblyVersion>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
<AssemblyVersion>9.0.0.0</AssemblyVersion>
<AssemblyVersion>10.0.0.0</AssemblyVersion>
<AssemblyVersion>11.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.0.5.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>netstandard</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.1.0.0</AssemblyVersion>
</AssemblyInfo>
<Attributes>
<Attribute FrameworkAlternate="netframework-4.0">
<AttributeName Language="C#">[System.Runtime.TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]</AttributeName>
<AttributeName Language="F#">[<System.Runtime.TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")>]</AttributeName>
</Attribute>
</Attributes>
<ReturnValue>
<ReturnType>System.Void</ReturnType>
</ReturnValue>
<Parameters />
<Docs>
<summary>Starts execution of a background operation.</summary>
<remarks>
<format type="text/markdown"><.
:::code language="csharp" source="~/snippets/csharp/System.ComponentModel/BackgroundWorker/IsBusy/Form1.cs" id="Snippet2":::
:::code language="vb" source="~/snippets/visualbasic/System.ComponentModel/BackgroundWorker/IsBusy/Form1.vb" id="Snippet2":::
]]></format>
</remarks>
<exception cref="T:System.InvalidOperationException">
<see cref="P:System.ComponentModel.BackgroundWorker.IsBusy" /> is <see langword="true" />.</exception>
<altmember cref="E:System.ComponentModel.BackgroundWorker.DoWork" />
<related type="Article" href="/dotnet/framework/winforms/controls/how-to-run-an-operation-in-the-background">How to: Run an Operation in the Background</related>
<related type="Article" href="/dotnet/standard/threading/managed-threading-best-practices">Managed Threading Best Practices</related>
<related type="Article" href="/dotnet/framework/winforms/controls/how-to-download-a-file-in-the-background">How to: Download a File in the Background</related>
</Docs>
</Member>
<Member MemberName="RunWorkerAsync">
<MemberSignature Language="C#" Value="public void RunWorkerAsync (object argument);" FrameworkAlternate="dotnet-uwp-10.0;netcore-1.0;netcore-1.1;netcore-2.0;netcore-2.1;netcore-2.2;netcore-3.0;netcore-3.1;netframework-2.0;netframework-3.0;netframework-3.5;netframework-4.0;netframework-4.5;netframework-4.5.1;netframework-4.5.2;netframework-4.6;netframework-4.6.1;netframework-4.6.2;netframework-4.7;netframework-4.7.1;netframework-4.7.2;netframework-4.8;netframework-4.8.1;netstandard-2.0;netstandard-2.1" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig instance void RunWorkerAsync(object argument) cil managed" />
<MemberSignature Language="DocId" Value="M:System.ComponentModel.BackgroundWorker.RunWorkerAsync(System.Object)" />
<MemberSignature Language="VB.NET" Value="Public Sub RunWorkerAsync (argument As Object)" />
<MemberSignature Language="F#" Value="member this.RunWorkerAsync : obj -> unit" Usage="backgroundWorker.RunWorkerAsync argument" />
<MemberSignature Language="C++ CLI" Value="public:
 void RunWorkerAsync(System::Object ^ argument);" />
<MemberSignature Language="C#" Value="public void RunWorkerAsync (object? argument);" FrameworkAlternate="net-10.0;net-11.0;net-5.0;net-6.0;net-7.0;net-8.0;net-9.0" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>System.ComponentModel.EventBasedAsync</AssemblyName>
<AssemblyVersion>4.0.10.0</AssemblyVersion>
<AssemblyVersion>4.1.0.0</AssemblyVersion>
<AssemblyVersion>4.1.1.0</AssemblyVersion>