本文整理汇总了C#中System.Data.SqlClient.TdsParserStateObject.WaitForAccumulatedWrites方法的典型用法代码示例。如果您正苦于以下问题:C# TdsParserStateObject.WaitForAccumulatedWrites方法的具体用法?C# TdsParserStateObject.WaitForAccumulatedWrites怎么用?C# TdsParserStateObject.WaitForAccumulatedWrites使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Data.SqlClient.TdsParserStateObject
的用法示例。
在下文中一共展示了TdsParserStateObject.WaitForAccumulatedWrites方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TdsExecuteRPC
//.........这里部分代码省略.........
// if it is not supplied, simply write out our default collation, otherwise, write out the one attached to the parameter
SqlCollation outCollation = (param.Collation != null) ? param.Collation : _defaultCollation;
Debug.Assert(_defaultCollation != null, "_defaultCollation is null!");
WriteUnsignedInt(outCollation.info, stateObj);
stateObj.WriteByte(outCollation.sortId);
}
if (0 == codePageByteSize)
WriteParameterVarLen(mt, actualSize, isNull, stateObj, isDataFeed);
else
WriteParameterVarLen(mt, codePageByteSize, isNull, stateObj, isDataFeed);
Task writeParamTask = null;
// write the value now
if (!isNull)
{
if (isSqlVal)
{
writeParamTask = WriteSqlValue(value, mt, actualSize, codePageByteSize, param.Offset, stateObj);
}
else
{
// for codePageEncoded types, WriteValue simply expects the number of characters
// For plp types, we also need the encoded byte size
writeParamTask = WriteValue(value, mt, param.GetActualScale(), actualSize, codePageByteSize, param.Offset, stateObj, param.Size, isDataFeed);
}
}
if (!sync)
{
if (writeParamTask == null)
{
writeParamTask = stateObj.WaitForAccumulatedWrites();
}
if (writeParamTask != null)
{
Task task = null;
if (completion == null)
{
completion = new TaskCompletionSource<object>();
task = completion.Task;
}
AsyncHelper.ContinueTask(writeParamTask, completion,
() => TdsExecuteRPC(rpcArray, timeout, inSchema, stateObj, isCommandProc, sync, completion,
startRpc: ii, startParam: i + 1),
connectionToDoom: _connHandler,
onFailure: exc => TdsExecuteRPC_OnFailure(exc, stateObj));
// Take care of releasing the locks
if (releaseConnectionLock)
{
task.ContinueWith(_ =>
{
_connHandler._parserLock.Release();
}, TaskScheduler.Default);
releaseConnectionLock = false;
}
return task;
}
}
#if DEBUG
else
示例2: WriteBulkCopyValue
//.........这里部分代码省略.........
case TdsEnums.SQLNCHAR:
case TdsEnums.SQLNVARCHAR:
case TdsEnums.SQLNTEXT:
ccb = ((isSqlType) ? ((SqlString)value).Value.Length : ((string)value).Length) * 2;
break;
case TdsEnums.SQLXMLTYPE:
// Value here could be string or XmlReader
if (value is XmlReader)
{
value = MetaType.GetStringFromXml((XmlReader)value);
}
ccb = ((isSqlType) ? ((SqlString)value).Value.Length : ((string)value).Length) * 2;
break;
default:
ccb = metadata.length;
break;
}
}
else
{
Debug.Assert(metatype.IsLong &&
((metatype.SqlDbType == SqlDbType.VarBinary && value is StreamDataFeed) ||
((metatype.SqlDbType == SqlDbType.VarChar || metatype.SqlDbType == SqlDbType.NVarChar) && value is TextDataFeed) ||
(metatype.SqlDbType == SqlDbType.Xml && value is XmlDataFeed)),
"Stream data feed should only be assigned to VarBinary(max), Text data feed should only be assigned to [N]VarChar(max), Xml data feed should only be assigned to XML(max)");
}
// Expected the text length in data stream for bulk copy of text, ntext, or image data.
//
if (metatype.IsLong)
{
switch (metatype.SqlDbType)
{
case SqlDbType.Text:
case SqlDbType.NText:
case SqlDbType.Image:
stateObj.WriteByteArray(s_longDataHeader, s_longDataHeader.Length, 0);
WriteTokenLength(metadata.tdsType, ccbStringBytes == 0 ? ccb : ccbStringBytes, stateObj);
break;
case SqlDbType.VarChar:
case SqlDbType.NVarChar:
case SqlDbType.VarBinary:
case SqlDbType.Xml:
case SqlDbType.Udt:
// plp data
WriteUnsignedLong(TdsEnums.SQL_PLP_UNKNOWNLEN, stateObj);
break;
}
}
else
{
WriteTokenLength(metadata.tdsType, ccbStringBytes == 0 ? ccb : ccbStringBytes, stateObj);
}
if (isSqlType)
{
internalWriteTask = WriteSqlValue(value, metatype, ccb, ccbStringBytes, 0, stateObj);
}
else if (metatype.SqlDbType != SqlDbType.Udt || metatype.IsLong)
{
internalWriteTask = WriteValue(value, metatype, metadata.scale, ccb, ccbStringBytes, 0, stateObj, metadata.length, isDataFeed);
if ((internalWriteTask == null) && (_asyncWrite))
{
internalWriteTask = stateObj.WaitForAccumulatedWrites();
}
Debug.Assert(_asyncWrite || stateObj.WaitForAccumulatedWrites() == null, "Should not have accumulated writes when writing sync");
}
else
{
WriteShort(ccb, stateObj);
internalWriteTask = stateObj.WriteByteArray((byte[])value, ccb, 0);
}
#if DEBUG
//In DEBUG mode, when SetAlwaysTaskOnWrite is true, we create a task. Allows us to verify async execution paths.
if (_asyncWrite && internalWriteTask == null && SqlBulkCopy.SetAlwaysTaskOnWrite == true)
{
internalWriteTask = Task.FromResult<object>(null);
}
#endif
if (internalWriteTask != null)
{ //i.e. the write was async.
resultTask = WriteBulkCopyValueSetupContinuation(internalWriteTask, saveEncoding, saveCollation, saveCodePage, saveLCID);
}
}
finally
{
if (internalWriteTask == null)
{
_defaultEncoding = saveEncoding;
_defaultCollation = saveCollation;
_defaultCodePage = saveCodePage;
_defaultLCID = saveLCID;
}
}
return resultTask;
}
示例3: TdsExecuteRPC
//.........这里部分代码省略.........
// if it is not supplied, simply write out our default collation, otherwise, write out the one attached to the parameter
SqlCollation outCollation = (param.Collation != null) ? param.Collation : _defaultCollation;
Debug.Assert(_defaultCollation != null, "_defaultCollation is null!");
WriteUnsignedInt(outCollation.info, stateObj);
stateObj.WriteByte(outCollation.sortId);
}
if (0 == codePageByteSize)
WriteParameterVarLen(mt, actualSize, isNull, stateObj, isDataFeed);
else
WriteParameterVarLen(mt, codePageByteSize, isNull, stateObj, isDataFeed);
Task writeParamTask = null;
// write the value now
if (!isNull) {
if (isSqlVal) {
writeParamTask = WriteSqlValue(value, mt, actualSize, codePageByteSize, param.Offset, stateObj);
}
else {
// for codePageEncoded types, WriteValue simply expects the number of characters
// For plp types, we also need the encoded byte size
writeParamTask = WriteValue(value, mt, isParameterEncrypted ? (byte)0 : param.GetActualScale(), actualSize, codePageByteSize, isParameterEncrypted ? 0 : param.Offset, stateObj, isParameterEncrypted ? 0 : param.Size, isDataFeed);
}
}
// Send encryption metadata for encrypted parameters.
if (isParameterEncrypted) {
writeParamTask = WriteEncryptionMetadata(writeParamTask, encryptedParameterInfoToWrite, stateObj);
}
if (!sync) {
if (writeParamTask == null) {
writeParamTask = stateObj.WaitForAccumulatedWrites();
}
if (writeParamTask != null) {
Task task = null;
if (completion == null) {
completion = new TaskCompletionSource<object>();
task = completion.Task;
}
AsyncHelper.ContinueTask(writeParamTask, completion,
() => TdsExecuteRPC(cmd, rpcArray, timeout, inSchema, notificationRequest, stateObj, isCommandProc, sync, completion,
startRpc: ii, startParam: i + 1),
connectionToDoom: _connHandler,
onFailure: exc => TdsExecuteRPC_OnFailure(exc, stateObj));
// Take care of releasing the locks
if (releaseConnectionLock) {
task.ContinueWith(_ => {
_connHandler._parserLock.Release();
}, TaskScheduler.Default);
releaseConnectionLock = false;
}
return task;
}
}
#if DEBUG
else {
Debug.Assert(writeParamTask == null, "Should not have a task when executing sync");
}
#endif
} // parameter for loop