关于等待任务完成和线程同步的主题.
我目前有一个迭代,我已经包含在Parallel.ForEach中.在下面的例子中,我在评论中提出了一些关于如何最好地处理循环的优雅终止的问题(.NET 4.0);
private void myFunction()
{
IList<string> iListOfItems = new List<string>();
// populate iListOfItems
CancellationTokenSource cts = new CancellationTokenSource();
ParallelOptions po = new ParallelOptions();
po.MaxDegreeOfParallelism = 20; // max threads
po.CancellationToken = cts.Token;
try
{
var myWcfProxy = new myWcfClientSoapClient();
if (Parallel.ForEach(iListOfItems, po, (item, loopsate) =>
{
try
{
if (_requestedToStop)
loopsate.Stop();
// long running blocking WS call, check before and after
var response = myWcfProxy.ProcessIntervalConfiguration(item);
if (_requestedToStop)
loopsate.Stop();
// perform some local processing of the response object
} …
Run Code Online (Sandbox Code Playgroud) 我有点陷入困境,为什么我似乎无法通过下面的语句获得插入行的"新标识".SCOPE_IDENTITY()
只返回null.
declare @WorkRequestQueueID int
declare @LastException nvarchar(MAX)
set @WorkRequestQueueID = 1
set @LastException = 'test'
set nocount off
DELETE dbo.WorkRequestQueue
OUTPUT
DELETED.MessageEnvelope,
DELETED.Attempts,
@LastException,
GetUtcdate(), -- WorkItemPoisened datetime
DELETED.WorkItemReceived_UTC
INTO dbo.FaildMessages
FROM dbo.WorkRequestQueue
WHERE
WorkRequestQueue.ID = @WorkRequestQueueID
IF @@ROWCOUNT = 0
RAISERROR ('Record not found', 16, 1)
SELECT Cast(SCOPE_IDENTITY() as int)
Run Code Online (Sandbox Code Playgroud)
任何援助都将非常感激.
现在我使用这样的解决方法.
declare @WorkRequestQueueID int
declare @LastException nvarchar(MAX)
set @WorkRequestQueueID = 7
set @LastException = 'test'
set nocount on
set xact_abort on
DECLARE @Failed TABLE
(
MessageEnvelope …
Run Code Online (Sandbox Code Playgroud) 将 SOAP 字段元素留空会导致本机类型的强制转换错误。(遗憾的是不能使用 xsi:nil="true" 由于客户端限制)
将 WCF 合同本机类型标记为 nullable<> 似乎不足以阻止向客户端返回以下错误。
字符串 '' 不是有效的布尔值。在 System.Xml.XmlConvert.ToBoolean(String s) 在 System.Xml.XmlConverter.ToBoolean(String value) System.FormatException
有谁知道指示 DataContractSerializer 将要反序列化的空元素转换为 null 的最佳方法吗?
我的示例 WCF 服务合同;
[ServiceContract()]
public interface IMyTest
{
[OperationContract]
string TestOperation(TestRequest request);
}
[ServiceBehavior()]
public class Settings : IMyTest
{
public string TestOperation(TestRequest request)
{
if (request.TestDetail.TestBool.HasValue)
return "Bool was specified";
else
return "Bool was null";
}
}
[DataContract()]
public class TestRequest
{
[DataMember(IsRequired = true)]
public int ID { get; set; }
[DataMember(IsRequired = true)] …
Run Code Online (Sandbox Code Playgroud) 我试图在PowerGui 3.0中点源脚本文件,但我得到的只是;
术语".\ PowerShell.Common.ps1"未被识别为cmdlet,函数,脚本文件或可操作程序的名称.检查名称的拼写,或者如果包含路径,请验证路径是否正确,然后重试.在D:\ TFS\SharePoint\Dev\Deploy\AutoSPInstaller\SP2010\AutoSPInstaller\AutoSPInstallerFunctionsCustom.ps1:6 char:31 +.\.PowerShell.Common.ps1 <<<< + CategoryInfo:ObjectNotFound:(.\ PowerShell.Common. ps1:String)[],CommandNotFoundException + FullyQualifiedErrorId:CommandNotFoundException
并且powerGui随后不在所述文件中提供我的脚本功能 - 在父脚本的上下文敏感列表中.
文件"PowerShell.Common.ps1"与AutoSPInstallerFunctionsCustom.ps1位于同一目录中.感谢您的帮助
.net ×1
datamember ×1
foreach ×1
nullable ×1
powergui ×1
powershell ×1
sql-server ×1
t-sql ×1
wcf ×1