本文整理汇总了C#中System.ComponentModel.DoWorkEventArgs类的典型用法代码示例。如果您正苦于以下问题:C# DoWorkEventArgs类的具体用法?C# DoWorkEventArgs怎么用?C# DoWorkEventArgs使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DoWorkEventArgs类属于System.ComponentModel命名空间,在下文中一共展示了DoWorkEventArgs类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BackgroundWorker_DoWork
protected void BackgroundWorker_DoWork(object sender, DoWorkEventArgs e)
{
Debug.Assert(e.Argument is CalculateGroupsAsyncArgs);
CalculateGroupsAsyncArgs tmpArgs = (CalculateGroupsAsyncArgs)e.Argument;
AnalyzerBase[] analyzers = tmpArgs.Analyzers.ToArray();
IGraph graph = tmpArgs.Graph;
LinkedList<AnalyzeResultBase> results = new LinkedList<AnalyzeResultBase>();
foreach (AnalyzerBase analyzer in analyzers)
{
AnalyzeResultBase result;
if (!analyzer.tryAnalyze(graph, m_oBackgroundWorker, out result)) // The user cancelled.
{
e.Cancel = true;
m_oBackgroundWorker.ReportProgress(0, "Cancelled.");
return;
}
results.AddLast(result);
}
Debug.Assert(results != null);
e.Result = results;
m_oBackgroundWorker.ReportProgress(100, new ProgressState(100, "Writing Back..", true));
}
示例2: BwDoWork
static void BwDoWork(object sender, DoWorkEventArgs e)
{
Console.WriteLine("BwDoWork INI");
using (var awe = new AdventureWorksEntities())
{
var c = new Contato()
{
Nome = "Adão",
Sobrenome = "da Silva",
PasswordHash = "abc",
PasswordSalt = "xyz",
rowguid = Guid.NewGuid(),
ModifiedDate = DateTime.Now
};
awe.Contatos.AddObject(c);
awe.SaveChanges();
e.Result = c.ContactID;
}
Console.WriteLine("BwDoWork FIM");
}
示例3: AddFilesAndDirectoriesAsync
//bool toCancelReceive = false;
/// <summary>
/// Асинхронно и рекурсивно добавляет набор файлов и директорий в кассету в указанную коллекцию
/// и возвращает набор добавленных в базу данных XElement-записей - это для синхронизации
/// </summary>
/// <param name="filenamesAndCollectionId">К массиву имен файлов и директорий, последним элементом прикреплен (добавлен) идентификатор коллекции, в которую записываются внешние файлы</param>
/// <param name="worker"></param>
/// <param name="e"></param>
/// <returns></returns>
private IEnumerable<XElement> AddFilesAndDirectoriesAsync(string[] filenamesAndCollectionId,
BackgroundWorker worker, DoWorkEventArgs e)
{
List<XElement> addedElements = new List<XElement>();
string[] filenames = filenamesAndCollectionId.Take(filenamesAndCollectionId.Length - 1).ToArray();
string collectionId = filenamesAndCollectionId[filenamesAndCollectionId.Length - 1];
// правильно посчитаю число вводимых файлов
int fnumber = 0;
foreach (string fn in filenames)
{
if (File.Exists(fn)) { if (fn != "Thumbs.db") fnumber++; }
else fnumber += 1 + CountTotalFiles(new DirectoryInfo(fn));
}
// а теперь добавлю файлы и директории с
int count = 0;
foreach (string fname in filenames)
{
if (worker.CancellationPending) break;
if (File.Exists(fname))
{
if (fname != "Thumbs.db")
addedElements.AddRange(this.cass.AddFile(new FileInfo(fname), collectionId));
count++;
worker.ReportProgress(100 * count / fnumber);
}
else if (Directory.Exists(fname))
{
//smallImageFullNames.AddRange(this.cass.AddDirectory(new DirectoryInfo(fname), collectionId));
addedElements.AddRange(AddDirectoryAsync(new DirectoryInfo(fname), collectionId, ref count, fnumber, worker));
}
}
return addedElements;
}
示例4: backgroundWorker1_DoWork
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
try
{
this.backgroundWorker1.ReportProgress(0, string.Format("{0}に接続中・・・", this.uri));
this.client = new WebClient();
while (this.client.IsBusy)
{
Thread.Sleep(100);
if (this.backgroundWorker1.CancellationPending)
{
return;
}
}
Stream stream = this.client.OpenRead(this.uri);
this.backgroundWorker1.ReportProgress(0, string.Format("{0}に接続完了", this.uri));
this.backgroundWorker1.ReportProgress(0, string.Format("データを読み込み中", this.uri));
StreamReader reader = new StreamReader(stream);
string str = reader.ReadToEnd();
this.xmltext = str;
reader.Close();
this.backgroundWorker1.ReportProgress(0, string.Format("完了", this.uri));
}
catch (Exception exception)
{
throw new Exception(exception.Message);
}
}
示例5: bgwCode_DoWork
private void bgwCode_DoWork(object sender, DoWorkEventArgs e)
{
System.ComponentModel.BackgroundWorker worker = sender as System.ComponentModel.BackgroundWorker;
int value = (int)e.Argument;
e.Result = Treatment((int)e.Argument, (int)e.Argument, worker, e);
}
示例6: backgroundWorker1_DoWork
void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
BackgroundWorker worker = sender as BackgroundWorker;
string fn = (string)e.Argument;
while (true)
{
Process proc = new Process();
proc.StartInfo.FileName = System.IO.Directory.GetCurrentDirectory() + "\\ffmpeg.exe";
proc.StartInfo.Arguments = "-i " + fn + " -y " + fn.Substring(0, fn.Length - (fn.Length - fn.LastIndexOf("."))) + "_Audio.mp3";
proc.StartInfo.RedirectStandardError = true;
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.CreateNoWindow = true;
proc.Start();
StreamReader reader = proc.StandardError;
string line;
while ((line = reader.ReadLine()) != null)
{
if (worker.CancellationPending == true)
{
e.Cancel = true;
break;
}
if (line.Contains("No such file or directory"))
{
error = true;
break;
}
worker.ReportProgress(0, line);
}
proc.Close();
break;
}
}
示例7: backgroundWorkerConnect_DoWork
//worker thread
//-------------
private void backgroundWorkerConnect_DoWork(object sender, DoWorkEventArgs e)
{
DeviceSettings sessionInfo = (DeviceSettings)e.Argument;
BackgroundWorker worker = (BackgroundWorker)sender;
try
{
_connecting = true;
_connected = _session.OpenSession(sessionInfo.Host, sessionInfo.Username, sessionInfo.Password);
//check remember settings
if (_connected)
{
if (checkBoxSave.Checked)
SettingsUtils.saveSettings(new ToolSettings
{
Device = _selectedModem,
Username = sessionInfo.Username,
Password = sessionInfo.Password,
Host = sessionInfo.Host,
});
else
SettingsUtils.deleteSettings();
//refresh
ThreadUtils.setButtonTextFromThread(buttonConnect, "Refreshing, please wait...");
_session.RefreshData();
}
}
catch (Exception ex)
{
MessageBox.Show("Unexpected error occurred. Debug info: " + ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
示例8: bwImportTransactions_DoWork
private void bwImportTransactions_DoWork(object sender, DoWorkEventArgs e)
{
Basket basket = e.Argument as Basket;
ofxFileImporter.UpdateBalance(basket);
decimal numberOfTransactions = basket.ofxFile.Transactions.Count;
decimal currentPosition = 0;
List<Merchant> nationalMerchants = Merchant.NationalMerchants();
foreach (Transaction Transaction in basket.ofxFile.Transactions)
{
if (ofxFileImporter.TransactionDoesNotExist(Transaction, basket.BankAccount.BankAccountID))
{
Transaction transaction = Transaction.CheckBankTricks(Transaction, basket.BankAccount);
string categoryName = "";
if (transaction.TransactionType == "ATM" && transaction.BankMemo != "STAMP PURCHASE")
categoryName = "Miscellaneous: Cash";
if (categoryName == "")
categoryName = ofxFileImporter.FindCategory(transaction, nationalMerchants);
int orginalTransactionID = ofxFileImporter.InsertIntoOringalTransaction(basket.BankAccount,
transaction, categoryName);
ofxFileImporter.InsertIntoSplitTransction(categoryName, orginalTransactionID, transaction);
}
currentPosition++;
decimal percent = currentPosition / numberOfTransactions;
decimal percentnew = percent * 100;
bwImportTransactions.ReportProgress((int)percentnew);
}
}
示例9: MakeDataSource
protected override System.Data.DataSet MakeDataSource(DoWorkEventArgs e)
{
if (base.m_Period.DateEndIsNull || base.m_Period.DateBeginIsNull)
{
Messages.ShowMessage("Заполните период");
return null;
}
Area area = new Area();
if (this.groupAdressesView.GetSelectedAddresses().get_Count() != 0)
{
area.SaveChanges();
area.SaveAddresses(this.groupAdressesView.GetSelectedAddresses());
area.SaveChanges();
}
ObjectList<Organization> selectedOrganizations = this.selectOrgs1.SelectedOrganizations;
ObjectList<ServiceTypeOld> serviceTypes = this.selectServiceTypes1.ServiceTypes;
System.DateTime fromPeriod = base.m_Period.DateBeginIsNull ? Constants.NullDate : base.m_Period.DateBegin;
System.DateTime toPeriod = base.m_Period.DateEndIsNull ? Constants.NullDate : base.m_Period.DateEnd;
if ((fromPeriod == Constants.MinDate) || (toPeriod == Constants.MinDate))
{
Messages.ShowMessage("Не заданы даты!");
return null;
}
System.Data.DataSet set = Mappers.SimpleReportMapper.GetJnReportByChargeVacations(area.Id, selectedOrganizations, serviceTypes, fromPeriod, toPeriod);
set.Tables.get_Item(0).set_TableName("tuning");
set.Tables.get_Item(1).set_TableName("crit");
set.Tables.get_Item(2).set_TableName("data");
area.DeleteWithRelations();
return set;
}
示例10: backgroundWorker1_DoWork
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
HtmlAgilityPack.HtmlDocument htmlDoc = new HtmlAgilityPack.HtmlDocument();
//// There are various options, set as needed
htmlDoc.OptionFixNestedTags = true;
htmlDoc.LoadHtml(DownloadPage("http://www.pogdesign.co.uk/cat/showselect.php"));
HtmlNodeCollection series = htmlDoc.DocumentNode.SelectNodes("//div[@class='butthold'][" + (int)e.Argument + "]/div");
ElementCount = series.Count;
if (series != null)
{
for (int i = 1; i < ElementCount; i++)
{
Console.WriteLine(series[i].SelectSingleNode("label").InnerText.Trim());
backgroundWorker1.ReportProgress(i, correctTitle(series[i].SelectSingleNode("label").InnerText.Trim()));
}
}
else
{
Console.WriteLine("NULL NODE");
}
}
示例11: backgroundWorker1_DoWork
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
BackgroundWorker worker = sender as BackgroundWorker;
while (socketManager.CountClients < maxClients)
{
if (worker.CancellationPending)
{
socketManager.Stop();
e.Cancel = true;
break;
}
if (socketManager.HasIncoming)
{
SocketHandler player = socketManager.ConnectPlayer();
string playerName = player.WaitForName();
Debug.WriteLine(playerName);
}
string state = string.Format("Waiting for {0} players..",
maxClients -
socketManager.CountClients);
worker.ReportProgress(socketManager.CountClients * 100 / maxClients,
state);
Thread.Sleep(10);
}
}
示例12: AsyncPlayFilesWorker
private void AsyncPlayFilesWorker(object sender, DoWorkEventArgs e)
{
var songs = (Collection<ApiAudioSong>)e.Argument;
if (songs == null)
return;
if (!_parent.IsConnected())
return;
_parent.JsonCommand("AudioPlaylist.Clear", null);
var i = 0;
var args = new JsonObject();
foreach (var apiAudioSong in songs)
{
if (((BackgroundWorker)sender).CancellationPending)
{
e.Cancel = true;
return;
}
args["songid"] = apiAudioSong.IdSong;
_parent.JsonCommand("AudioPlaylist.Add", args);
if (i != 0) continue;
_parent.JsonCommand("AudioPlaylist.Play", null);
i++;
}
}
示例13: bwResolver_DoWork
private void bwResolver_DoWork(object sender, DoWorkEventArgs e) {
POP3 pop3 = this.pop3;
if (pop3 == null)
return;
while (true) {
MailItem next = null;
ListViewItem lviIt = null;
Sync.Send(delegate(object state) {
foreach (ListViewItem lvi in lvm.Items) {
if (lvi.ImageIndex == 0) {
next = (MailItem)lvi.Tag;
lviIt = lvi;
break;
}
}
}, null);
if (next == null || lviIt == null)
break;
String rows = pop3.Top(next.i, 1);
String text = "?";
try {
EML_Reader er = new EML_Reader();
er.read(new StringReader(rows));
text = er.main.mlSubject;
}
catch (Exception) {
}
Sync.Send(delegate(object state) {
lviIt.ImageIndex = 1;
lviIt.Text = text;
}, null);
}
}
示例14: Mux
public void Mux(object sender, DoWorkEventArgs e)
{
var inputM2TsFlags = _keepM2TsAudio ? null : "--no-audio";
var inputMkvFlags = _keepM2TsAudio ? "--no-audio" : null;
var args = new ArgumentList();
// Chapter file
args.AddIfAllNonEmpty("--chapters", _inputChaptersPath);
// Output file
args.AddAll("-o", _outputMkvPath);
// Input M2TS file
args.AddNonEmpty("--no-video", inputM2TsFlags, _inputM2TsPath);
// If an input chapter file is specified, exclude chapters from the input MKV file
if (!string.IsNullOrEmpty(_inputChaptersPath))
args.Add("--no-chapters");
// Input MKV file
args.AddNonEmpty(inputMkvFlags, _inputMkvPath);
Execute(args, sender, e);
}
示例15: backgroundWorker1_DoWork
// Background do
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
// download and save
QuizManage.GetFromDb((int)numericUpDown1.Value,
(checkBox1.Checked ? (int)numericUpDown2.Value : -1));
QuizManage.Save();
}