本文整理汇总了C#中System.ComponentModel.AsyncOperation.PostOperationCompleted方法的典型用法代码示例。如果您正苦于以下问题:C# AsyncOperation.PostOperationCompleted方法的具体用法?C# AsyncOperation.PostOperationCompleted怎么用?C# AsyncOperation.PostOperationCompleted使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.ComponentModel.AsyncOperation
的用法示例。
在下文中一共展示了AsyncOperation.PostOperationCompleted方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CompletionMethod
private void CompletionMethod(string output, Exception ex, bool cancelled, AsyncOperation asyncOp)
{
lock (userStateDictionary)
{
userStateDictionary.Remove(asyncOp.UserSuppliedState);
}
// results of the operation
asyncOp.PostOperationCompleted(onCompletedDelegate,
new LongTaskCompletedEventArgs(output, ex, cancelled, asyncOp.UserSuppliedState));
}
示例2: DispatchCompleting
private void DispatchCompleting(MessageData responsemsg, Exception ex, bool canceled, AsyncOperation asyncOper)
{
if (!canceled)
{
lock (_userStateToLifetime.SyncRoot)
{
_userStateToLifetime.Remove(asyncOper.UserSuppliedState);
}
}
TransmitCompletedEventArgs eventArgs = new TransmitCompletedEventArgs(responsemsg, ex, canceled, asyncOper.UserSuppliedState);
asyncOper.PostOperationCompleted(onCompletedDelegate, eventArgs);
}
示例3: WorkerThreadStart
private void WorkerThreadStart(AsyncOperation asyncOp, object userState, object argument)
{
Exception error = null;
bool cancelled = false;
DoWorkEventArgs e = new DoWorkEventArgs(userState, argument);
try
{
this.OnDoWork(e);
if (e.Cancel) cancelled = true;
}
catch (Exception ex)
{
error = ex;
}
lock (userStateToLifetime.SyncRoot)
{
userStateToLifetime.Remove(asyncOp.UserSuppliedState);
}
WorkerCompletedEventArgs arg = new WorkerCompletedEventArgs(error, cancelled, asyncOp.UserSuppliedState, argument);
asyncOp.PostOperationCompleted(this.SendOrPostWorkerCompleted, arg);
}
示例4: PrepareToRaiseCompletedEvent
internal void PrepareToRaiseCompletedEvent(AsyncOperation asyncOP, ResolveCompletedEventArgs args)
{
asyncOP.PostOperationCompleted(OnResolveCompletedDelegate, args);
lock (m_PeerNameResolverHelperListLock)
{
PeerNameResolverHelper helper = m_PeerNameResolverHelperList[args.UserState];
if (helper == null)
{
Logging.P2PTraceSource.TraceEvent(TraceEventType.Critical, 0, "userState for which we are about to call Completed event does not exist in the pending async list");
}
else
{
Logging.P2PTraceSource.TraceEvent(TraceEventType.Information, helper.TraceEventId,
"userState {0} is being removed from the pending async list", args.UserState.GetHashCode());
m_PeerNameResolverHelperList.Remove(args.UserState);
}
}
}
示例5: JobActionWorker
private void JobActionWorker(AsyncOperation asyncOp, ActionType action, string reason, string label, bool suppressError)
{
Exception exception = null;
#pragma warning disable 56500
try
{
switch (action)
{
case ActionType.Start:
DoStartJobLogic(null);
break;
case ActionType.Stop:
DoStopJob();
break;
case ActionType.Suspend:
DoSuspendJob();
break;
case ActionType.Resume:
DoResumeJob(label);
break;
case ActionType.Abort:
DoAbortJob(reason);
break;
case ActionType.Terminate:
DoTerminateJob(reason, suppressError);
break;
}
}
catch (Exception e)
{
// Called on a background thread, need to include any exception in
// event arguments.
exception = e;
}
#pragma warning restore 56500
var eventArgs = new AsyncCompletedEventArgs(exception, false, asyncOp.UserSuppliedState);
var container = new AsyncCompleteContainer { EventArgs = eventArgs, Action = action };
// End the task. The asyncOp object is responsible
// for marshaling the call.
asyncOp.PostOperationCompleted(JobActionAsyncCompleted, container);
}
示例6: CompletionMethod
// This is the method that the underlying, free-threaded
// asynchronous behavior will invoke. This will happen on
// an arbitrary thread.
private void CompletionMethod(
List<ProxyInfo> proxylistOk,
Exception exception,
bool canceled,
AsyncOperation asyncOp)
{
// If the task was not previously canceled,
// remove the task from the lifetime collection.
if (!canceled)
{
lock (userStateToLifetime.SyncRoot)
{
userStateToLifetime.Remove(asyncOp.UserSuppliedState);
}
}
// Package the results of the operation in a
// CalculatePrimeCompletedEventArgs.
CompletedEventArgs e =
new CompletedEventArgs(
proxylistOk,
exception,
canceled,
asyncOp.UserSuppliedState);
// End the task. The asyncOp object is responsible
// for marshaling the call.
asyncOp.PostOperationCompleted(onCompletedDelegate, e);
// Note that after the call to OperationCompleted,
// asyncOp is no longer usable, and any attempt to use it
// will cause an exception to be thrown.
}
示例7: Generate
//.........这里部分代码省略.........
report2.Dispose();
}
report = new NoticeReport(renderedNotices);
this.m_GeneratedReport = report;
}
if ((this.m_ThreadExceptions.Count > 0) || this.m_IsCancelled)
{
ex = null;
this.m_ThreadExceptions.TryDequeue(out ex);
this.AbortOperation(asyncOp, ex, (System.TimeSpan) (System.DateTime.Now - now));
}
else
{
if ((this.m_NoticeCache.get_Count() > 0) && (this.m_Exporter != null))
{
logger.Info("Экспорт по домам управляющих компаний");
int num9 = (int) ((this.m_Exporter.MaxPageCount * this.m_Template.AccountsInTemplate) / this.m_Template.PageCount);
CachedNoticeInfoComparer comparer = new CachedNoticeInfoComparer();
try
{
foreach (string str in this.m_NoticeCache.Keys)
{
this.m_NoticeCache[str].Sort(comparer);
logger.Info("Экспорт домов УК " + str);
for (int n = 0; n < this.m_NoticeCache[str].get_Count(); n = (int) (n + num9))
{
System.Text.StringBuilder builder = new System.Text.StringBuilder();
int num11 = this.m_NoticeCache[str].get_Count();
if (num11 != 0)
{
int maxPageCount = this.m_Exporter.MaxPageCount;
int num13 = (int) (num11 - (n + maxPageCount));
num13 = (num13 < 1) ? ((int) 0) : num13;
using (StiReport report3 = new StiReport())
{
report3.IsRendered = true;
report3.NeedsCompiling = false;
report3.RenderedPages.Clear();
System.IO.DirectoryInfo info = new System.IO.DirectoryInfo(System.IO.Path.Combine(this.m_Exporter.DestinationPath, str));
if (!info.get_Exists())
{
info.Create();
}
string file = System.IO.Path.Combine(info.get_FullName(), string.Format("{0}_{1}.pdf", str, n / num9));
for (int num14 = n; num14 < (num11 - num13); num14 = (int) (num14 + 1))
{
System.IO.FileInfo info2 = new System.IO.FileInfo(this.m_NoticeCache[str].get_Item(num14).CacheFilePath);
if (info2.get_Exists())
{
byte[] bytes = System.IO.File.ReadAllBytes(info2.get_FullName());
StiReport report4 = new StiReport();
report4.LoadPackedDocument(bytes);
report4.ReportUnit = report3.ReportUnit;
foreach (StiPage page in report4.RenderedPages)
{
page.Report = report3;
page.Guid = System.Guid.NewGuid().ToString().Replace("-", "");
report3.RenderedPages.Add(page);
}
if (this.m_Exporter.DualPageExportMode && ((report4.RenderedPages.get_Count() % 2) != 0))
{
StiPage page2 = new StiPage(report3) {
IsRendered = true,
Orientation = report4.RenderedPages[0].Orientation,
Guid = System.Guid.NewGuid().ToString().Replace("-", "")
};
report3.RenderedPages.Add(page2);
}
builder.AppendLine(this.m_NoticeCache[str].get_Item(num14).FullAddress);
}
}
report3.ExportDocument(StiExportFormat.Pdf, file);
System.IO.File.WriteAllText(file + ".txt", builder.ToString());
}
}
}
}
logger.Info("Очистка дискового кэша");
System.IO.Directory.Delete(System.IO.Path.Combine(this.m_Exporter.DestinationPath, this.m_ExportCacheDirectoryName), true);
}
catch (System.Exception exception19)
{
ex = new NoticeGenerationException("Ошибка при экспорте извещений, сгруппированных по УК", exception19);
this.AbortOperation(asyncOp, ex, (System.TimeSpan) (System.DateTime.Now - now));
return;
}
}
System.TimeSpan timeSpent = (System.TimeSpan) (System.DateTime.Now - now);
logger.Info("Операция успешно завершена. Время выполнения " + timeSpent.ToString());
logger.Info("Всего отрендерено: " + ((int) this.m_TotalRendered));
if (asyncOp != null)
{
GenerationCompletedEventArgs args = new GenerationCompletedEventArgs(timeSpent, null, false, asyncOp.get_UserSuppliedState()) {
GeneratedReport = report
};
asyncOp.PostOperationCompleted(this.onCompletedDelegate, args);
}
this.Reset();
}
}
示例8: processCompletionMethod
// This is the method that the underlying, free-threaded
// asynchronous behavior will invoke. This will happen on
// a worker thread
private void processCompletionMethod(
Task task,
Exception exception,
bool canceled,
AsyncOperation asyncOp)
{
// If the task was not previously canceled,
// remove the task from the lifetime collection.
if (!canceled)
{
lock (processJobs)
{
processJobs.Remove(asyncOp.UserSuppliedState);
}
}
// Package the results of the operation in EventArgs
TaskEventArgs e = new TaskEventArgs(task, exception, canceled, asyncOp.UserSuppliedState);
// End the task. The asyncOp object is responsible
// for marshaling the call.
asyncOp.PostOperationCompleted(onProcessingCompleteDelegate, e);
// Note that after the call to OperationCompleted,
// asyncOp is no longer usable, and any attempt to use it
// will cause an exception to be thrown.
}
示例9: PrepareToRaiseCreateContactCompletedEvent
internal void PrepareToRaiseCreateContactCompletedEvent(AsyncOperation asyncOP, CreateContactCompletedEventArgs args)
{
asyncOP.PostOperationCompleted(OnCreateContactCompletedDelegate, args);
}
示例10: completionMethod
private void completionMethod(object data, Exception ex, bool cancelled, AsyncOperation asyncOp)
{
if (!cancelled) {
lock (userStateToLifetime) {
userStateToLifetime.Remove(asyncOp.UserSuppliedState);
}
var e = new OperationCompletedEventArgs(data, ex, cancelled, asyncOp.UserSuppliedState);
asyncOp.PostOperationCompleted(onCompletedCallback, e);
}
}
示例11: processFieldWorker
private void processFieldWorker(string filePath, IProcessingSettings settings,
AsyncOperation asyncOp)
{
Exception e = null;
Task task = new Task();
try
{
if (settings is TextFieldProcessingSettings)
{
task = _syncClient.ProcessTextField(filePath, settings as TextFieldProcessingSettings);
}
else if (settings is BarcodeFieldProcessingSettings)
{
task = _syncClient.ProcessBarcodeField(filePath, settings as BarcodeFieldProcessingSettings);
}
else if (settings is CheckmarkFieldProcessingSettings)
{
task = _syncClient.ProcessCheckmarkField(filePath, settings as CheckmarkFieldProcessingSettings);
}
else
{
throw new ArgumentException("Invalid type of processing settings");
}
// Notify that upload was completed
Task uploadedTask = new Task(task.Id, TaskStatus.Submitted);
UploadCompletedEventArgs uploadCompletedEventArgs = new UploadCompletedEventArgs(uploadedTask, asyncOp.UserSuppliedState);
asyncOp.Post(onUploadCompletedDelegate, uploadCompletedEventArgs);
// Wait until task finishes
startTaskMonitorIfNecessary();
_taskList.AddTask(task);
task = waitUntilTaskFinishes(task);
}
catch (Exception ex)
{
e = ex;
}
lock (processJobs)
{
processJobs.Remove(asyncOp.UserSuppliedState);
}
bool canceled = false;
// Package the results of the operation in EventArgs
TaskEventArgs ev = new TaskEventArgs(task, e, canceled, asyncOp.UserSuppliedState);
// End the task. The asyncOp object is responsible
// for marshaling the call.
asyncOp.PostOperationCompleted(onProcessingCompleteDelegate, ev);
}
示例12: RefreshWeaveDataCompletionMethod
// This is the method that the underlying, free-threaded
// asynchronous behavior will invoke. This will happen on
// an arbitrary thread.
private void RefreshWeaveDataCompletionMethod(Exception error, bool cancelled, AsyncOperation asyncOperation)
{
// If the task was not previously canceled,
// remove the task from the lifetime collection.
if (!cancelled)
{
lock (this)
{
userStateToLifetime.Remove(asyncOperation.UserSuppliedState);
}
}
RefreshWeaveDataCompletedEventArgs e = new RefreshWeaveDataCompletedEventArgs(error, cancelled, asyncOperation.UserSuppliedState);
asyncOperation.PostOperationCompleted(state => OnRefreshWeaveDataCompleted((RefreshWeaveDataCompletedEventArgs)state), e);
}
示例13: GetBitmapWorker
private void GetBitmapWorker(string path, AsyncOperation asyncOp)
{
Exception error = null;
bool cancelled = false;
Bitmap bitmap = null;
try
{
bitmap = GetBitmap(path);
}
catch (Exception ex)
{
error = ex;
}
cancelled = IsTaskCanceled(asyncOp.UserSuppliedState);
GetBitmapAsyncCancel(asyncOp.UserSuppliedState);
asyncOp.PostOperationCompleted(getBitmapAsyncCompletedDelegate, new GetBitmapCompletedEventArgs(error, cancelled, asyncOp.UserSuppliedState, bitmap));
}
示例14: InvokeOperationCompeted
private void InvokeOperationCompeted(AsyncOperation asyncOp, SendOrPostCallback callback, UploadFileCompletedEventArgs eventArgs)
{
if (this.m_IsExpired)
eventArgs = new UploadFileCompletedEventArgs("", new Exception(Properties.Settings.Default.UploadExpired), false, this.m_AsyncOperation.UserSuppliedState);
if (Interlocked.CompareExchange<AsyncOperation>(ref this.m_AsyncOperation, null, asyncOp) == asyncOp)
{
var _originalWebResponse = Interlocked.Exchange<WebResponse>(ref this.m_WebResponse, null);
closeResponse(_originalWebResponse);
this.completeUploadClientState();
asyncOp.PostOperationCompleted(callback, eventArgs);
}
}
示例15: ProcessWorker
/// <summary>
/// 异步工作线程。
/// </summary>
/// <param name="task">输入路径到输出路径</param>
/// <param name="processingPlugins">处理插件</param>
/// <param name="outputPlugin">输出插件</param>
/// <param name="asyncOp">跟踪异步操作的生存期。</param>
private void ProcessWorker(KeyValuePair<string, string> task, IEnumerable<IProcessingPlugin> processingPlugins, IOutputPlugin outputPlugin, AsyncOperation asyncOp)
{
// 创建处理任务上下文对象。
ImageProcessorTaskContext imageProcessorTaskContext = new ImageProcessorTaskContext();
imageProcessorTaskContext.TotalProcedureCount = processingPlugins.Count() + 2;
// 为 ProcessingPlugin 添加事件处理方法。
foreach (var processingPlugin in processingPlugins)
{
// ! 重要,保证多任务处理事件唯一,也许以后可能有更好的方法。
lock (processingPlugin)
{
processingPlugin.ProcessProgressChanged -= processingPlugin_ProcessProgressChangedDelegate;
processingPlugin.ProcessCompleted -= getBitmapCompletedDelegate;
processingPlugin.ProcessProgressChanged += processingPlugin_ProcessProgressChangedDelegate;
processingPlugin.ProcessCompleted += getBitmapCompletedDelegate;
}
imageProcessorTaskContext.ProcessingPluginQueue.Enqueue(processingPlugin);
}
// 添加到对应关系中。
lock ((userStateToTaskContext as ICollection).SyncRoot)
{
userStateToTaskContext[asyncOp.UserSuppliedState] = imageProcessorTaskContext;
}
// 创建 UserState 对象。
object userState = Guid.NewGuid();
// 添加到对应关系中。
lock ((taskUserStateToUserState as ICollection).SyncRoot)
{
taskUserStateToUserState[userState] = asyncOp.UserSuppliedState;
}
// 开始获取 Bitmap。
getBitmapManager.GetBitmapAsync(task.Key, userState);
while (imageProcessorTaskContext.ProcessingPluginQueue.Count > 0)
{
// 等待上步操作完成。
imageProcessorTaskContext.AutoResetEvent.WaitOne();
if (IsTaskCancelled(asyncOp.UserSuppliedState) || imageProcessorTaskContext.Error != null)
{
break;
}
else
{
IProcessingPlugin processingPlugin = imageProcessorTaskContext.ProcessingPluginQueue.Dequeue();
userState = Guid.NewGuid();
imageProcessorTaskContext.CurrentProcessingPlugin = processingPlugin;
imageProcessorTaskContext.CurrentProcessingPluginUserState = userState;
lock ((taskUserStateToUserState as ICollection).SyncRoot)
{
taskUserStateToUserState[userState] = asyncOp.UserSuppliedState;
}
processingPlugin.ProcessAsync(imageProcessorTaskContext.Bitmap, userState);
}
}
if (!IsTaskCancelled(asyncOp.UserSuppliedState) && imageProcessorTaskContext.Error == null)
{
// 等待最后处理完成。
imageProcessorTaskContext.AutoResetEvent.WaitOne();
// 输出。
outputPlugin.Output(imageProcessorTaskContext.Bitmap, task.Value);
}
bool cancelled = IsTaskCancelled(asyncOp.UserSuppliedState);
lock ((userStateToLifetime as ICollection).SyncRoot)
{
userStateToLifetime.Remove(asyncOp.UserSuppliedState);
}
asyncOp.PostOperationCompleted(processAsyncCompletedDelegate, new AsyncCompletedEventArgs(imageProcessorTaskContext.Error, cancelled, asyncOp.UserSuppliedState));
}