我正在使用.Net 4构建一个简单的Windows服务,当我想在启动服务之前延迟5分钟时会出现问题.
protected override void OnStart(string[] args)
{
// make a 5 min delay
// do something
}
Run Code Online (Sandbox Code Playgroud)
但几秒钟后服务停止并给我一个超时错误(在事件日志中看到这个).我该怎么办?
我正在使用一个由多个应用程序和服务组成的系统,几乎都使用SQL数据库.
Windows服务在不同的时间做不同的事情,我想跟踪它们.这意味着在某些已部署的系统上我们看到机器在CPU上运行很高,我们看到sql进程运行正常,但我们无法确定哪个服务负责它.
我想知道性能计数器是否适合这项工作.
基本上我希望能够在某个时刻看到哪些服务醒来并正在处理某些事情.
在我看来,我最终perfcounter可能只有每个服务的值为0或1,以显示它是否正在做某事,但这似乎不是正常用法perfcounters.
性能计数器是否合适?
你认为我应该以不同的方式追踪这个吗?
Parent_ObjectiveID并且identity是int?数据类型.在我的程序中应该返回一个对象,但它给出了一个错误:Sequence contains no elements.
int? identity = null;
Objective currentObjective = (from p in cd.Objective
where p.Parent_ObjectiveID == identity
select p).Single();
Run Code Online (Sandbox Code Playgroud)
虽然,如果我将identity变量替换为null.它有效,但我不明白.
currentObjective = (from p in cd.Objective
where p.Parent_ObjectiveID == null
select p).Single();
Run Code Online (Sandbox Code Playgroud)
发生了什么?
更新1:
我这样做了:
if (identity == null)
{
currentObjective = (from p in cd.Objective
where p.Parent_ObjectiveID == null
select p).Single();
}
else
{
currentObjective = (from p in cd.Objective
where p.Parent_ObjectiveID == identity
select p).Single();
}
Run Code Online (Sandbox Code Playgroud)
但我真的不喜欢它.
给出以下XML.
<?xml version="1.0" encoding="UTF-8"?>
<xmldata>
<Products>
<ProductCode>M406789</ProductCode>
<ProductID>858</ProductID>
<ProductName>M406789 Ignition Box</ProductName>
<ProductDescriptionShort><img alt="" src="/v/vspfiles/assets/images/alliance_small.jpg" align="right" />Ignition Box</ProductDescriptionShort>
<ListPrice>134.2200</ListPrice>
<ProductPrice>80.5300</ProductPrice>
<SalePrice>59.9500</SalePrice>
</Products>
</xmldata>
Run Code Online (Sandbox Code Playgroud)
这是脚本的相关部分.
Set xNewDoc = xData.responseXML 'ResponseXml returns DOMDocument object
Set ProductCode = xNewDoc.SelectSingleNode("//ProductCode")
Set ListPrice = xNewDoc.SelectSingleNode("//ListPrice")
x=Len(ListPrice.Text)
newlp = Left(ListPrice.Text,x-2)
Set ProductPrice = xNewDoc.SelectSingleNode("//ProductPrice")
x=Len(ProductPrice.Text)
newpp = Left(ProductPrice.Text,x-2)
Set SalePrice = xNewDoc.SelectSingleNode("//SalePrice")
x=Len(SalePrice.Text)
newsp = Left(SalePrice.Text,x-2)
Set ProductName = xNewDoc.SelectSingleNode("//ProductName")
Run Code Online (Sandbox Code Playgroud)
如果缺少上面加载的xml和节点(假设为"SalePrice"),则脚本将失败.如何测试以查看节点是否存在以使其不会失败.我过去在Stack上看过这个东西,但似乎无法找到它.
我是一名初学程序员,从C#和Web服务开始.
在Service.cs我的Web服务文件中,我创建了一个ReadXMLFile()方法,我尝试读取现有的XML文件,从中获取数据并将其放入我在IService.cs文件中创建的相应属性(DataMembers).
我的问题是我的代码基本上没有做任何事情.我已经尝试过寻找网站和教程,但实际上并没有太多,特别是像我这样的初学者.任何人都知道我应该怎么做,因为我到目前为止所做的事情显然是错误的.
以下是我的ReadXMLFile()方法.
void ReadXMLFile()
{
XmlTextReader reader = new XmlTextReader("ClassRoll.xml");
reader.Read();
while (reader.Read())
{
if (reader.Name == "id")
{
id = reader.ReadString();
}
else if (reader.Name == "firstname")
{
link = reader.ReadString();
}
else if (reader.Name == "lastname")
{
description = reader.ReadString();
}
else if (reader.Name == "count")
{
description = reader.ReadString();
}
else if (reader.Name == "testscore")
{
description = reader.ReadString();
}
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的xml文件的一个例子
<classroll>
<student>
<id>101010</id>
<lastname>Smith</lastname> …Run Code Online (Sandbox Code Playgroud) 我正在运行一些只需要运行一次的代码,但它依赖于外部资源而且可能会失败.我希望错误出现在事件日志中,但我不希望用户看到它.我想尽可能避免使用自定义错误页面.
我可以捕获异常并将其自己写入事件日志,但我担心我不能保证asp.net事件源的名称会是什么(它似乎会根据框架版本而改变.)我也是无法创建我自己的事件源,因为它需要管理权限.
我目前正在努力的方法是一个黑客(它还没有工作),它看起来像这样:
public void Init(HttpApplication context)
{
try
{
throw new Exception("test"); // This is where the code that errors would go
}
catch (Exception ex)
{
HttpContext.Current.Application.Add("CompilationFailed", ex);
}
}
private void context_BeginRequest(object sender, EventArgs e)
{
if (HttpContext.Current.Application.AllKeys.Contains("CompilationFailed"))
{
// It failed on Init - we can't throw an exception there so lets try it here
var origEx = (Exception)HttpContext.Current.Application["CompilationFailed"];
// Only ever do this once
HttpContext.Current.Application.Remove("CompilationFailed");
// This should just look like a normal page load …Run Code Online (Sandbox Code Playgroud) 我创建了一个包含简单存储过程的数据库,用于删除,插入,选择和更新数据库的三个表中的记录.除了我的删除语句之外,它们都有效.我Procedure or function has too many arguments尝试时收到一条消息.我尝试删除它拥有的一个参数,最后删除了所有表的记录,而不是我所针对的记录.我究竟做错了什么?我有一种感觉错误在我的SQL脚本中,但我不知道我可以做些什么来使其工作.
消息:
过程或函数Delete_Special指定了太多参数.
我的SQL脚本:
CREATE PROCEDURE [Delete_Special]
@ThisID INT
AS
DELETE FROM [Daily_Specials]
WHERE @ThisID = [ID]
GO
Run Code Online (Sandbox Code Playgroud)
调用存储过程的事件:
Protected Sub BTN_DeleteEvt_Click(sender As Object, e As EventArgs)
SQL_Specials.Delete()
End Sub
Run Code Online (Sandbox Code Playgroud)
删节标记:
<asp:SqlDataSource ID="SQL_Specials" runat="server" DeleteCommand="Delete_Special" DeleteCommandType="StoredProcedure">
<DeleteParameters>
<asp:ControlParameter ControlID="GV_Eagles_Specials" Name="ThisID" PropertyName="SelectedIndex"
Type="Int32" />
</DeleteParameters>
</asp:SqlDataSource>
<asp:GridView ID="GV_Eagles_Specials" runat="server" DataSourceID="SQL_Specials" AutoGenerateColumns="False">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:Button ID="BTN_EditSpecial" runat="server" CssClass="BigText" Text="Edit" OnClick="BTN_EditEvent_Click" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Date" HeaderText="Date" SortExpression="Date" HtmlEncode="False" DataFormatString="{0:MM/dd/yyyy}" />
<asp:BoundField DataField="Special" HeaderText="Special" …Run Code Online (Sandbox Code Playgroud) 我有 6400 多条记录在循环中。对于其中的每一个:我通过针对类似于邮局使用的内容(查找地址)的内容进行测试来检查地址是否有效。我需要仔细检查我撤回的邮政编码是否匹配。
唯一的问题是邮政编码可能以多种不同的格式输入,例如:
OP6 6YH
OP66YH
OP6 6YH.
Run Code Online (Sandbox Code Playgroud)
If Replace(strPostcode," ","") = Replace(xmlAddress.selectSingleNode("//postcode").text," ","") Then
我想从字符串中删除所有空格。如果我执行上面的替换,它会删除第一个示例的空间,但为第三个示例保留一个空间。
我知道我可以使用循环语句删除这些,但相信这会使脚本运行非常缓慢,因为它必须循环遍历 6400 多条记录才能删除空格。
还有其他方法吗?
<Requirement Description="description" Operation="Configure">
<Action ID="1000" Name="Split">
<Contract>
<Parameter Name="Version">4</Parameter>
<Parameter Name="DefaultServer">192.168.00.</Parameter>
<Parameter Name="DefaultUser">administrator</Parameter>
<Parameter Name="DefaultPassword">password</Parameter>
<Parameter Name="DefaultDomain">192.168.00.00</Parameter>
<Parameter Name="Split">1</Parameter>
</Contract>
</Action>
</Requirement>
Run Code Online (Sandbox Code Playgroud)
从上面的XML文档中,我的目标是从VBScript替换属性default server和default domain的IP地址.
Set objXMLDoc = CreateObject("Microsoft.XMLDOM")
objXMLDoc.async = False
objXMLDoc.load(XMLFullPath)
Set NodeList = objXMLDoc.documentElement.SelectNodes("//Parameter")
NodeList(i).nodeName
Run Code Online (Sandbox Code Playgroud)
将名称命名为Parameter,并NodeList(i).Text为我提供4,IP地址,管理员等值.但是我无法获取属性名称,因此我可以直接更改属性的值.
我试图使用的代码就是这个.
Dim oNode
Set oNode = XmlDoc.SelectSingleNode("/Record/CelloXml/Integration/Case/Hearing/Court/NodeID")
Dim iIndex
Set iIndex = (CInt((oNode.Text).substring(0,1))) - 1
Run Code Online (Sandbox Code Playgroud)
我想使用它iIndex来决定arraylist中的元素以返回到父应用程序.
我目前得到的错误是我需要一个文本对象 oNode.Text
我在这做错了什么?
c# ×5
vbscript ×4
xml ×3
asp.net ×2
xml-parsing ×2
event-log ×1
linq ×1
linq-to-sql ×1
nullable ×1
replace ×1
sql-server ×1
t-sql ×1
vb.net ×1
web-services ×1