本文整理汇总了C#中BackgroundWorker.RunWorkASync方法的典型用法代码示例。如果您正苦于以下问题:C# BackgroundWorker.RunWorkASync方法的具体用法?C# BackgroundWorker.RunWorkASync怎么用?C# BackgroundWorker.RunWorkASync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BackgroundWorker
的用法示例。
在下文中一共展示了BackgroundWorker.RunWorkASync方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Build
/// <summary>
/// 构建项目
/// </summary>
/// <param name="filepath"></param>
public virtual void Build(string filepath)
{
var builder = UpdatePackageBuilder.Instance;
var project = AuProject.LoadFile(filepath);
if (project == null)
{
BuilderFailed(null, new ApplicationException(SR.UnableOpenProject), null);
return;
}
builder.AuProject = project;
var bgw = new BackgroundWorker();
bgw.DoWork += (s, e) => builder.Build(e);
bgw.WorkFailed += (s, e) => BuilderFailed(project, e.Exception, builder.BuiltUpdateInfo);
bgw.WorkCompleted += (s, e) => BuildSuccess(project, builder.Result, builder.BuiltUpdateInfo);
bgw.WorkerProgressChanged += (s, e) => UpdateProgress(e.Progress);
OnWorkerInitialized();
bgw.RunWorkASync();
}
示例2: BeginCheckUpdateInProcess
/// <summary>
/// 开始检测更新
/// </summary>
/// <returns>返回是否成功开始检查</returns>
/// <exception cref="System.InvalidOperationException"></exception>
public bool BeginCheckUpdateInProcess()
{
var url = Context.UpdateInfoFileUrl;
if (string.IsNullOrEmpty(url)) throw new InvalidOperationException(SR.Updater_AssemblyNotMarkedAsUpdateable);
if (Context.IsInUpdating) return false;
var bgw = new BackgroundWorker()
{
WorkerSupportReportProgress = true
};
bgw.DoWork += DownloadUpdateInfoInternal;
bgw.WorkFailed += (s, e) =>
{
Context.IsInUpdating = false;
Context.Exception = e.Exception;
Trace.TraceWarning("检测更新信息失败:" + e.Exception.Message, e.Exception.ToString());
OnError();
};
bgw.WorkCompleted += (s, e) =>
{
if (Context.UpdateInfo == null) return;
Context.IsInUpdating = false;
if (Context.CurrentVersionTooLow)
{
OnMinmumVersionRequired();
}
else if (!Context.HasUpdate)
{
OnNoUpdatesFound();
}
else OnUpdatesFound();
};
bgw.WorkerProgressChanged += (s, e) => OnOperationProgressChanged(e);
Context.IsInUpdating = true;
bgw.RunWorkASync();
//启动外部清理进程。
CleanTemp();
return true;
}
示例3: BeginUpdate
/// <summary>
/// 开始进行更新
/// </summary>
internal void BeginUpdate()
{
var bgw = new BackgroundWorker() { WorkerSupportReportProgress = true };
bgw.DoWork += UpdateInternal;
bgw.WorkerProgressChanged += (s, e) => OnOperationProgressChanged(e);
bgw.WorkFailed += (s, e) =>
{
Context.IsInUpdating = false;
Context.Exception = e.Exception;
Trace.TraceWarning("更新中断,发生错误:" + e.Exception.Message, e.Exception.ToString());
OnError();
};
bgw.WorkCompleted += (s, e) =>
{
Context.IsInUpdating = false;
};
Context.IsInUpdating = true;
bgw.RunWorkASync();
CleanTemp();
}
示例4: BeginUpdate
/// <summary>
/// 开始进行更新
/// </summary>
internal void BeginUpdate()
{
var bgw = new BackgroundWorker() { WorkerSupportReportProgress = true };
bgw.DoWork += UpdateInternal;
bgw.WorkerProgressChanged += (s, e) => OnDownloadProgressChanged(e);
bgw.WorkFailed += (s, e) =>
{
this.Exception = e.Exception;
OnError();
};
bgw.RunWorkASync();
}
示例5: BeginCheckUpdateInProcess
/// <summary>
/// 开始检测更新
/// </summary>
public void BeginCheckUpdateInProcess()
{
if (string.IsNullOrEmpty(this.UpdateUrl)) throw new InvalidOperationException(DME.Updater.SR.Updater_AssemblyNotMarkedAsUpdateable);
if (_inRun) return;
var bgw = new BackgroundWorker()
{
WorkerSupportReportProgress = true
};
bgw.DoWork += DownloadUpdateInfoInternal;
bgw.WorkFailed += (s, e) =>
{
_inRun = false;
this.Exception = e.Exception;
OnError();
};
bgw.WorkCompleted += (s, e) =>
{
if (this.UpdateInfo == null) return;
if (!string.IsNullOrEmpty(UpdateInfo.RequiredMinVersion))
{
if (new Version(UpdateInfo.RequiredMinVersion) > CurrentVersion)
{
OnMinmumVersionRequired();
return;
}
}
var newVer = new Version(UpdateInfo.AppVersion);
if (newVer <= CurrentVersion)
{
OnNoUpdatesFound();
}
else OnUpdatesFound();
_inRun = false;
};
bgw.WorkerProgressChanged += (s, e) =>
{
OnDownloadProgressChanged(e);
};
_inRun = true;
bgw.RunWorkASync();
}