本文整理汇总了C#中AsyncResult.SetAsCompleted方法的典型用法代码示例。如果您正苦于以下问题:C# AsyncResult.SetAsCompleted方法的具体用法?C# AsyncResult.SetAsCompleted怎么用?C# AsyncResult.SetAsCompleted使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AsyncResult
的用法示例。
在下文中一共展示了AsyncResult.SetAsCompleted方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BeginGetAccessControl
/// <summary>
/// Begins to get an ObjectSecurity object that encapsulates the access control list (ACL) entries for a specified object
/// </summary>
/// <param name="obj">The object whose AccessControl information you want to retrieve</param>
/// <param name="asyncCallback">The user-defined delegate that is called when the asynchronous operation has completed.</param>
/// <param name="asyncState">The user-defined object that qualifies or contains information about an asynchronous operation.</param>
/// <returns>An IAsyncResult that represents the asynchronous operation.</returns>
public IAsyncResult BeginGetAccessControl(object obj, AsyncCallback asyncCallback, object asyncState)
{
ISharedObjectEntry entry;
bool isContainer = false;
if (obj == this)
{
// Get the (ACL)s for the root namespace
entry = this;
isContainer = true;
}
else
{
if (obj is SharedCollection)
{
var collection = obj as SharedCollection;
CollectionEntry collectionEntry;
if (!this.CollectionsManager.TryGetValue(collection.Name, out collectionEntry))
{
throw new ArgumentException("obj is not being tracked by this client", "obj");
}
entry = collectionEntry;
isContainer = true;
}
else
{
ObjectEntry objectEntry;
this.ObjectsManager.TryGetValue(obj as INotifyPropertyChanged, out objectEntry);
entry = objectEntry;
}
}
// Client has previously cached the value, return it immediately
if (entry.ObjectSecurity != null)
{
var result = new AsyncResult<SharedObjectSecurity>(asyncCallback, 0);
result.SetAsCompleted(entry.ObjectSecurity, true);
return result;
}
var security = new SharedObjectSecurity(entry.Name, entry.Id, isContainer, new ETag(Guid.Empty));
SharedObjectSecurityPayload payload = new SharedObjectSecurityPayload(PayloadAction.Get, security, this.ClientId);
var getResult = new SharedAsyncResult<SharedObjectSecurity>(asyncCallback, payload.PayloadId);
this.EnqueueAsyncResult(getResult, payload.PayloadId);
this.SendPublishEvent(payload);
return getResult;
}
示例2: BeginGetGroupTrackerIds
public IAsyncResult BeginGetGroupTrackerIds( int group, AsyncCallback callback, object asyncState )
{
if ( group == TestGroup )
{
AsyncResult<int> result = new AsyncResult<int>( callback, asyncState );
result.SetAsCompleted( group, true );
return result;
}
{
GroupDef cachedResult;
if ( TryGetFromCache( group, out cachedResult ) )
{
AsyncResult<GroupDef> result = new AsyncResult<GroupDef>( callback, asyncState );
result.SetAsCompleted( cachedResult, true );
return result;
}
}
// Ensure that this instance is not used already for some other call:
int prevOp =
Interlocked.CompareExchange(
ref this.operation,
( int ) ( Operation.GetGroupTrackerIds ),
( int ) ( Operation.None ) );
if ( prevOp != ( int ) Operation.None )
{
throw new InvalidOperationException(
string.Format(
"Cannot use an instance of {0} for simultaneous operations. Call End* method first.",
this.GetType( )
)
);
}
string connString = Tools.ConnectionStringModifier.AsyncConnString;
// use parameter (rather than add groupId value to the string) to
// allow SQL Server cache execution plan for the query:
SqlConnection sqlConn = new SqlConnection( connString );
sqlConn.Open( );
try
{
this.sqlCmd = new SqlCommand( "GetGroupTrackerIds", sqlConn );
this.sqlCmd.CommandType = System.Data.CommandType.StoredProcedure;
// Use parameter, not formatted sql string - see above why
this.sqlCmd.Parameters.Add( "@GroupId", System.Data.SqlDbType.Int );
SqlParameter versionPar = this.sqlCmd.Parameters.Add( "@Version", System.Data.SqlDbType.Int );
versionPar.Direction = System.Data.ParameterDirection.Output;
SqlParameter displayUserMessagesPar = this.sqlCmd.Parameters.Add( "@DisplayUserMessages", System.Data.SqlDbType.Bit );
displayUserMessagesPar.Direction = System.Data.ParameterDirection.Output;
SqlParameter startTsPar = this.sqlCmd.Parameters.Add( "@StartTs", System.Data.SqlDbType.DateTime );
startTsPar.Direction = System.Data.ParameterDirection.Output;
this.sqlCmd.Parameters[0].Value = group;
this.groupId = group;
return this.sqlCmd.BeginExecuteReader( callback, asyncState );
}
catch ( Exception exc )
{
Log.ErrorFormat( "Can't start getting group IDs for group {0}: {1}", group, exc.Message );
sqlConn.Close( );
throw;
}
}
示例3: BeginReadBody
public IAsyncResult BeginReadBody(byte[] buffer, int offset, int count, AsyncCallback callback, object state)
{
if (currentResult != null)
throw new InvalidOperationException("Async operation is already pending.");
if (callback == null)
throw new ArgumentNullException("callback");
if (bodyDataReadWithHeaders.Count > 0)
{
int bytesRead;
var result = new AsyncResult<int>(callback, state);
bytesRead = Math.Min(bodyDataReadWithHeaders.Count, count);
Buffer.BlockCopy(bodyDataReadWithHeaders.Array, bodyDataReadWithHeaders.Offset, buffer, offset, bytesRead);
if (bytesRead < bodyDataReadWithHeaders.Count)
bodyDataReadWithHeaders =
new ArraySegment<byte>(
bodyDataReadWithHeaders.Array,
bodyDataReadWithHeaders.Offset + bytesRead,
bodyDataReadWithHeaders.Count - bytesRead);
else
bodyDataReadWithHeaders = default(ArraySegment<byte>);
currentResult = result;
result.SetAsCompleted(bytesRead, true);
}
else if (socket != null)
{
var tcs = new TaskCompletionSource<int>();
currentResult = tcs.Task;
socket.Read(buffer, offset, count).ContinueWith(t =>
{
if (t.IsFaulted)
tcs.SetException(t.Exception);
else
tcs.SetResult(t.Result);
callback(tcs.Task);
});
}
else
{
var result = new AsyncResult<int>(callback, state);
currentResult = result;
result.SetAsCompleted(0, true);
}
return currentResult;
}