I want to know the best way to do this:
using (var backgroundWorker = new BackgroundWorker()) { DoWorkEventHandler doWorkHandler = null; doWorkHandler = (s, e) => { //Some expensive code goes here... backgroundWorker.DoWork -= doWorkHandler; //or //((BackgroundWorker)s).DoWork -= doWorkHandler; }; backgroundWorker.DoWork += doWorkHandler; RunWorkerCompletedEventHandler workerCompleted = null; workerCompleted = (s, e) => { //Update IU or something... backgroundWorker.RunWorkerCompleted -= workerCompleted; //or //((BackgroundWorker)s).RunWorkerCompleted -= workerCompleted; }; backgroundWorker.RunWorkerCompleted += workerCompleted; backgroundWorker.RunWorkerAsync(); }
x
1) What do you mean? Delete "doWorkHandler"? If so, you do not need to do this (as far as I know). Just like Ale , you just need to reuse the same bgw.
. , bgw , .
2) ( ). "" "s", , . s ( ).
- . . goo ( , , ). =)
, BackgroundWorker . , , , ( using.)
, backgroundWorker , , userState, RunWorkerCompletedEventArgs.
Source: https://habr.com/ru/post/1796094/More articles:Простая проверка операционной системы из HTML/JS - javascriptRequest for the presence / version of the browser plugin / etc. - javascriptIn a LINQ statement using closure, is it possible to specify where clause in closure? - closuresHow does the Java application server decide which encoding to send in the HTTP Content-type header? - javahttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1796093/what-happens-to-existing-ios-app-when-i-update&usg=ALkJrhiN8aruDiBJScu6cXKs12k-upIrSwПроблемы с часами CMAKE - visual-c++Convert date versus Where clause - sqlБудет ли это использование List чудом или беспорядком - listRetrieving CellArray values in a java data type - javaChild objects do not load when a query joins tables - c #All Articles