本文整理汇总了C#中QueueItem.Action方法的典型用法代码示例。如果您正苦于以下问题:C# QueueItem.Action方法的具体用法?C# QueueItem.Action怎么用?C# QueueItem.Action使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QueueItem
的用法示例。
在下文中一共展示了QueueItem.Action方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetTask
/// <summary>
/// Get a task from a queued item
/// </summary>
/// <param name="item">queue request item</param>
/// <returns>task</returns>
private HttpTask GetTask( QueueItem item )
{
HttpTask httpTask = null;
if ( item.Method == HttpMethod.Get ) {
httpTask = new GetTextHttpTask( item.Url );
}
else if ( item.FileData == null ) {
httpTask = new PostTextHttpTask( item.Url, item.PostData );
}
else {
httpTask = new FileUploadHttpTask( item.Url, item.PostData, item.FileData, item.FileFieldName, item.FileName );
}
httpTask.OnHttpRequestCompleted += ( state, stream, error ) => {
// first clean up the task pool internally
lock ( _tasks ) {
_tasks.Remove( httpTask );
}
if ( _taskCount == 0 ) {
_resetEvent.Set();
}
Interlocked.Increment( ref _taskCount );
// here all things done! May be error or canceled
item.Action( state, stream, error );
};
return httpTask;
}
示例2: GetTask
/// <summary>
/// Get a task from a queued item
/// </summary>
/// <param name="item">queue request item</param>
/// <returns>task</returns>
private HttpTask GetTask(QueueItem item)
{
HttpTask httpTask = null;
if (item.Method == HttpMethod.Get)
{
httpTask = new GetTextHttpTask(item.Url);
}
else
{
httpTask = new PostTextHttpTask(item.Url, item.PostData);
}
httpTask.HttpRequestCompleted += (state, stream, error) =>
{
lock (_lock)
{
_tasks.Remove(httpTask);
}
if (_taskCount == 0)
{
_resetEvent.Set();
}
Interlocked.Increment(ref _taskCount);
item.Action(state, stream, error);
};
return httpTask;
}
示例3: GetTask
/// <summary>
/// 从排队的项目中生成任务,加入下载列表
/// </summary>
/// <param name="item">排队项</param>
/// <returns>对应的任务</returns>
private ImageHttpGetTask GetTask( QueueItem item )
{
ImageHttpGetTask imageTask = new ImageHttpGetTask( item.Url );
imageTask.OnImageCreated += ( bitmap ) => {
item.Action( bitmap );
OnNewImageDownloaded( item.Url, bitmap );
};
imageTask.TaskCompleted += () => {
lock ( _tasks ) {
_tasks.Remove( imageTask );
}
if ( _taskCount == 0 ) {
_resetEvent.Set();
}
Interlocked.Increment( ref _taskCount );
};
return imageTask;
}