本文整理汇总了C#中System.ComponentModel.BackgroundWorker类的典型用法代码示例。如果您正苦于以下问题:C# BackgroundWorker类的具体用法?C# BackgroundWorker怎么用?C# BackgroundWorker使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BackgroundWorker类属于System.ComponentModel命名空间,在下文中一共展示了BackgroundWorker类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ParseTopPerson
public static void ParseTopPerson(string html, Action<List<Person>> finished)
{
BackgroundWorker bw = new BackgroundWorker();
bw.DoWork += new DoWorkEventHandler((sender, e) =>
{
List<Person> TopPerson = new List<Person>();
HtmlDocument hDoc = new HtmlDocument();
hDoc.LoadHtml(html);
var tableRows = hDoc.DocumentNode.SelectNodes(Constants.Instance.XPATH_GAME_TOP_RESULT);
foreach (var node in tableRows)
{
var results = ChildElementsInTableRow(node);
if (results.Count == Constants.Instance.COUNT_GAME_TOP_RESULT_COLUMNS)
{
var person = TopPersonFromStrings(results);
if (person.Total != 0)
{
TopPerson.Add(person);
}
}
}
finished(TopPerson);
});
bw.RunWorkerAsync();
}
示例2: AddDirectoryAsync
private IEnumerable<XElement> AddDirectoryAsync(DirectoryInfo dir, string collectionId, ref int count, int fnumber,
BackgroundWorker worker)
{
List<XElement> addedElements = new List<XElement>();
// добавление коллекции
string subCollectionId;
List<XElement> ae = this.cass.AddCollection(dir.Name, collectionId, out subCollectionId).ToList();
if (ae.Count > 0) addedElements.AddRange(ae);
count++;
foreach (FileInfo f in dir.GetFiles())
{
if (worker.CancellationPending) break;
if (f.Name != "Thumbs.db")
addedElements.AddRange(this.cass.AddFile(f, subCollectionId));
count++;
worker.ReportProgress(100 * count / fnumber);
}
foreach (DirectoryInfo d in dir.GetDirectories())
{
if (worker.CancellationPending) break;
addedElements.AddRange(AddDirectoryAsync(d, subCollectionId, ref count, fnumber, worker));
}
return addedElements;
}
示例3: ParseRecommends
public static void ParseRecommends(string html, Action<List<Recommend>> finished)
{
BackgroundWorker bw = new BackgroundWorker();
bw.DoWork += new DoWorkEventHandler((sender, e) =>
{
List<Recommend> allRecommends = new List<Recommend>();
HtmlDocument hDoc = new HtmlDocument();
hDoc.LoadHtml(html);
var tableRows = hDoc.DocumentNode.SelectNodes(Constants.Instance.XPATH_GAME_SHOW_RESULT);
foreach (var node in tableRows)
{
var results = ChildElementsInTableRow(node);
if (results.Count == Constants.Instance.COUNT_GAME_SHOW_RESULT_COLUMNS)
{
var rec = RecommendFromStrings(results);
if (IsValidRecommend(rec))
{
allRecommends.Add(rec);
}
}
}
finished(allRecommends);
});
bw.RunWorkerAsync();
}
示例4: ScannerProgress
public ScannerProgress(string folder, BackgroundWorker worker)
{
this.worker = worker;
InitializeComponent();
UpdateFolder(folder);
UpdateAction("");
}
示例5: CPromoCashableDetails
public CPromoCashableDetails(string RouteNumber, DateTime StartDate, DateTime EndDate,int UserNo)
{
InitializeComponent();
_worker = new BackgroundWorker();
_worker.WorkerReportsProgress = true;
_worker.WorkerSupportsCancellation = true;
CurrencySymbol = CurrencySymbol.GetCurrencySymbol();
this.RouteNumber = RouteNumber;
this.StartDate = StartDate;
this.EndDate = EndDate;
this.UserNo = UserNo;
// For resizing columns automatically.
GridView gv = lvPromoCashable.View as GridView;
if (gv != null)
{
foreach (GridViewColumn gvc in gv.Columns)
{
gvc.Width = gvc.ActualWidth;
if (gvc.Width == 0.0 || gvc.Width == 0)
gvc.Width = 0;
else
gvc.Width = Double.NaN;
}
}
}
示例6: UpdateCheck
private static void UpdateCheck()
{
Game.PrintChat("<font color='#33FFFF'> .: Orianna by trelli loaded :.");
var bgw = new BackgroundWorker();
bgw.DoWork += bgw_DoWork;
bgw.RunWorkerAsync();
}
示例7: Start
/// <summary>
/// Lance une tache dans un background worker.
/// </summary>
/// <param name="taskFunc">Tache à exécuter.</param>
/// <param name="completionAction">Action à réaliser après l'exécution. Recoit l'exception si une exception a eu lieu.</param>
public static void Start(Action taskFunc, Action<Exception> completionAction)
{
if (taskFunc == null)
{
throw new ArgumentNullException("taskFunc");
}
var backgroundWorker = new BackgroundWorker();
backgroundWorker.DoWork += new DoWorkEventHandler(
delegate
{
taskFunc();
});
backgroundWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(
delegate(object sender, RunWorkerCompletedEventArgs e)
{
if (completionAction != null)
{
completionAction(e.Error);
}
});
backgroundWorker.RunWorkerAsync();
}
示例8: Form1
public Form1()
{
InitializeComponent();
util = new Utility();
mainJobList = new BindingList<IndeedDetails>();
filtered = new List<IndeedDetails>();
sortKeeper = new GridSortBy();
//worker stuff
worker = new BackgroundWorker();
worker.DoWork += BackgroundWorkerDoWork;
worker.RunWorkerCompleted +=
BackgroundWorkerRunWorkerCompleted;
string file_name = @"C:\Users\apersinger\Documents\Misc\jsonjobs.txt";
string file_contents = util.OpenFile(file_name);
if(file_contents.Length > 0) {
data = util.DeserializeString(file_contents);
mainJobList = new BindingList<IndeedDetails>(data);
dataGridView1.DataSource = mainJobList;
}
txtURL.Text = "www.indeed.com";
txtLocation.Text = "california";
txtJobTitle.Text = "software";
btnFilterResults.Enabled = false;
}
示例9: PluginUpdaterForm
public PluginUpdaterForm(PluginManager pluginManager)
: base() {
InitializeComponent();
Text = "HeuristicLab Plugin Manager " + AssemblyHelpers.GetFileVersion(GetType().Assembly);
pluginManager.PluginLoaded += pluginManager_PluginLoaded;
pluginManager.PluginUnloaded += pluginManager_PluginUnloaded;
pluginManager.Initializing += pluginManager_Initializing;
pluginManager.Initialized += pluginManager_Initialized;
pluginDir = Application.StartupPath;
installationManager = new InstallationManager(pluginDir);
installationManager.PluginInstalled += new EventHandler<PluginInfrastructureEventArgs>(installationManager_PluginInstalled);
installationManager.PluginRemoved += new EventHandler<PluginInfrastructureEventArgs>(installationManager_PluginRemoved);
installationManager.PluginUpdated += new EventHandler<PluginInfrastructureEventArgs>(installationManager_PluginUpdated);
installationManager.PreInstallPlugin += new EventHandler<PluginInfrastructureCancelEventArgs>(installationManager_PreInstallPlugin);
installationManager.PreRemovePlugin += new EventHandler<PluginInfrastructureCancelEventArgs>(installationManager_PreRemovePlugin);
installationManager.PreUpdatePlugin += new EventHandler<PluginInfrastructureCancelEventArgs>(installationManager_PreUpdatePlugin);
this.pluginManager = pluginManager;
updatePluginsBackgroundWorker = new BackgroundWorker();
updatePluginsBackgroundWorker.DoWork += new DoWorkEventHandler(updatePluginsBackgroundWorker_DoWork);
updatePluginsBackgroundWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(updatePluginsBackgroundWorker_RunWorkerCompleted);
}
示例10: dooptimization
public bool dooptimization()
{
initialcount = points.Count;
currentpoint = 0;
finishedthreads = 0;
bws = new List<BackgroundWorker>();
for(int i=0;i<100;i++)
{
bws.Add(new BackgroundWorker());
bws[i] = new BackgroundWorker
{
WorkerReportsProgress = true,
WorkerSupportsCancellation = true
};
bws[i].DoWork += bw_DoWork;
bws[i].RunWorkerCompleted += bw_RunWorkerCompleted;
bws[i].RunWorkerAsync();//pass id???, what else?
}
while (finishedthreads!=100)
{
}
return true;
}
示例11: b_open_Click
private void b_open_Click(object sender_, RoutedEventArgs e_)
{
p_progress.Visibility = Visibility.Visible;
p_label.Visibility = Visibility.Visible;
bw_LoadFile = new BackgroundWorker();
bw_LoadFile.DoWork += (sender, e) =>
{
LCIO.OpenFile(bw_LoadFile);
};
bw_LoadFile.ProgressChanged += (sender, e) =>
{
p_label.Content = e.UserState;
};
bw_LoadFile.RunWorkerCompleted += (sender, e) =>
{
if (e.Error != null)
{
new TextMessage("Ошибка", e.Error.Message).ShowDialog();
}
p_progress.Visibility = Visibility.Hidden;
p_label.Visibility = Visibility.Hidden;
FLYOUT_OpenFile.IsOpen = false;
UpdateList();
};
bw_LoadFile.WorkerReportsProgress = true;
bw_LoadFile.RunWorkerAsync();
}
示例12: Lobby
public Lobby(Menu parent)
{
InitializeComponent();
ImageBrush myBrush = new ImageBrush();
myBrush.ImageSource = new BitmapImage(new Uri(".\\Resources\\icon_backarrow.png", UriKind.Relative));
bekk.Background = myBrush;
ImageBrush myBrush2 = new ImageBrush();
myBrush2.ImageSource = new BitmapImage(new Uri(".\\Resources\\icon_closebutton.png", UriKind.Relative));
klóz.Background = myBrush2;
this.parent = parent;
chatbox.Items.Clear();
refreshworker = new BackgroundWorker();
refreshworker.WorkerSupportsCancellation = true;
refreshworker.WorkerReportsProgress = true;
refreshworker.DoWork += refresh;
refreshworker.ProgressChanged += refreshUI;
activityworker = new BackgroundWorker();
activityworker.WorkerSupportsCancellation = true;
activityworker.DoWork += wait;
activityworker.RunWorkerCompleted += doActivity;
}
示例13: AtmosphereControl
public AtmosphereControl( )
{
InitializeComponent( );
// Populate texture resolution combo boxes
for ( int i = 4; i <= 1024; i *= 2 )
{
resolutionComboBox.Items.Add( i );
}
resolutionComboBox.SelectedItem = m_AtmosphereBuildParameters.HeightSamples;
m_AtmosphereBuilder = new AtmosphereBuilder( );
mH0UpDown.Value = ( decimal )m_AtmosphereModel.MieDensityScaleHeightFraction;
rH0UpDown.Value = ( decimal )m_AtmosphereModel.RayleighDensityScaleHeightFraction;
// TODO: AP: Remove bodges
inscatterDistanceFudgeUpDown.Value = ( decimal )m_AtmosphereModel.InscatterDistanceFudgeFactor;
outscatterDistanceFudgeUpDown.Value = ( decimal )m_AtmosphereModel.OutscatterDistanceFudgeFactor;
outscatterFudgeUpDown.Value = ( decimal )m_AtmosphereModel.OutscatterFudgeFactor;
mieFudgeUpDown.Value = ( decimal )m_AtmosphereModel.MieFudgeFactor;
rayleighFudgeUpDown.Value = ( decimal )m_AtmosphereModel.RayleighFudgeFactor;
m_Worker = new BackgroundWorker( );
m_Worker.WorkerReportsProgress = true;
m_Worker.WorkerSupportsCancellation = true;
m_Worker.DoWork += BuildWorkItem;
m_Worker.RunWorkerCompleted += WorkItemComplete;
m_Worker.ProgressChanged += BuildProgressChanged;
}
示例14: button1_Click
private void button1_Click(object sender, EventArgs e)
{
BackgroundWorker worker = new BackgroundWorker();
DataLocation loc = (DataLocation)ComboBoxSearchLocation.SelectedIndex;
worker.DoWork += (s, args) =>
{
try
{
Data.Letter[] LettersControl = null;
DateType _dType = DateType.All;
if (!CalendarAllCheckBox.Checked)
_dType = (DateType)ComboBoxDate.SelectedIndex + 1;
LettersControl = DBase.DataBase.GetLetters(TXTNumber.GetValue(), ComboProviders.Text, ComboTypes.Text, TXTFrom.Text, TXTTo.Text, TXTMoney.Text, TXTMoney2.Text, ComboUser.SelectedItem.ToString(), TextInc.Text, _dType, DateFrom.Value, DateTo.Value, loc);
args.Result = LettersControl;
}
catch { args.Result = null; }
};
worker.RunWorkerCompleted += (s, args) =>
{
if (args.Result == null) return;
AddLetters(args.Result as Data.Letter[]);
(this.ParentForm as Form1).WaitDisable();
};
(this.ParentForm as Form1).WaitEnable();
worker.RunWorkerAsync();
}
示例15: MakeDatZips
public static void MakeDatZips(object sender, DoWorkEventArgs e)
{
_bgw = sender as BackgroundWorker;
Program.SyncCont = e.Argument as SynchronizationContext;
if (Program.SyncCont == null)
{
_bgw = null;
return;
}
if (!Directory.Exists(_outputdir))
return;
if (_treeRow != null)
FindDats(_treeRow);
else
{
RvGame tGame = new RvGame();
tGame.DBRead((int)_gameId, true);
ExtractGame(tGame, _outputdir);
}
_bgw.ReportProgress(0, new bgwText("Creating Zips Complete"));
_bgw = null;
Program.SyncCont = null;
}