我想在Visual Studio 2008中调试一个程序.问题是如果它没有得到参数就会退出.这是从主要方法:
if (args == null || args.Length != 2 || args[0].ToUpper().Trim() != "RM")
{
Console.WriteLine("RM must be executed by the RSM.");
Console.WriteLine("Press any key to exit program...");
Console.Read();
Environment.Exit(-1);
}
Run Code Online (Sandbox Code Playgroud)
我不想评论它,然后在编译时再回来.如何在调试时使用参数启动程序?它被设置为StartUp项目.
我有一个Windows服务,并希望更改它的名称(因为它显示在服务应用程序中).但我不确定这样做的正确方法.它似乎是ServiceName属性,并通过我的解决方案搜索我发现:
namespace SI.AService.AService
{
partial class AService
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Component Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents …Run Code Online (Sandbox Code Playgroud) 我需要使用Powershell启用两个Windows功能.但我不知道他们的名字或如何找到他们.

到目前为止,我已设法安装IIS并使用此处找到的脚本停止默认应用程序池.
function InstallFeature($name) {
cmd /c "ocsetup $name /passive"
}
InstallFeature IIS-WebServerRole
InstallFeature IIS-WebServer
InstallFeature IIS-CommonHttpFeatures
InstallFeature IIS-DefaultDocument
InstallFeature IIS-DirectoryBrowsing
InstallFeature IIS-HttpErrors
InstallFeature IIS-HttpRedirect
InstallFeature IIS-StaticContent
InstallFeature IIS-HealthAndDiagnostics
InstallFeature IIS-CustomLogging
InstallFeature IIS-HttpLogging
InstallFeature IIS-HttpTracing
InstallFeature IIS-LoggingLibraries
InstallFeature IIS-Security
InstallFeature IIS-RequestFiltering
InstallFeature IIS-WindowsAuthentication
InstallFeature IIS-ApplicationDevelopment
InstallFeature IIS-NetFxExtensibility
InstallFeature IIS-ISAPIExtensions
InstallFeature IIS-ISAPIFilter
InstallFeature IIS-ASPNET
InstallFeature IIS-WebServerManagementTools
InstallFeature IIS-ManagementConsole
InstallFeature IIS-ManagementScriptingTools
import-module WebAdministration
Stop-WebAppPool DefaultAppPool
Run Code Online (Sandbox Code Playgroud)
解
寻找:
Get-WindowsFeature *ASP*
Get-WindowsFeature *activation*
Run Code Online (Sandbox Code Playgroud)
安装:
Add-WindowsFeature NET-Framework-45-ASPNET
Add-WindowsFeature NET-HTTP-Activation
Run Code Online (Sandbox Code Playgroud) 我有一个我正在尝试调试的Windows服务.现在即使当前的代码工作也无法启动.错误是:
Windows无法在本地计算机上启动MyService服务
错误1053:服务未及时响应启动或控制请求.
为了隔离错误,我试图评论一切.主要方法如下:
TextWriter tt = new StreamWriter(@"C:\startup.text", true);
tt.WriteLine("Starting up the service");
tt.Close();
ServiceBase[] ServicesToRun;
ServicesToRun = new ServiceBase[]
{
new MyService()
};
TextWriter tt2 = new StreamWriter(@"C:\startup.text", true);
tt2.WriteLine("Run...");
tt2.Close();
Run Code Online (Sandbox Code Playgroud)
它将"启动服务"和"运行..."打印到日志文件中.我也剥离了MyService的内部,所以它是空的.在任何代码周围都有一个try/catch,现在可以简化为上面的一些日志行.我从未输入将记录它的catch语句.
OnStart中的所有内容都已被注释掉:
protected override void OnStart(string[] args)
{
}
Run Code Online (Sandbox Code Playgroud)
所以我基本上没有想法.我认为错误是因为Start方法永远不会完成(或者不会在30秒内完成).是否有其他方法被调用?任何想法都表示赞赏.
额外信息: MyService中的构造函数为空.如果我插入一些Thread.Sleep(5000)行,则需要更长的时间才能弹出有关错误1053的错误消息.Main方法似乎必须退出(没有错误).
我想用所描述的通过Outlook发送电子邮件这里.只要我已经打开Outlook,它就可以正常工作.因此,例如,如果Outlook被最小化并且我执行我的代码,那么我可以发送电子邮件就好了.但如果Outlook关闭,那么我得到一个例外:
{System.Runtime.InteropServices.COMException (0x80004004): Operation aborted (Exception from HRESULT: 0x80004004 (E_ABORT))
at Microsoft.Office.Interop.Outlook._MailItem.get_Recipients()
at OutlookExample.Form1.btnSendEmail_Click(Object sender, EventArgs e) in C:\Users\abc\Documents\Visual Studio 2008\Projects\OutlookExample\OutlookExample\Form1.cs:line 28}
Run Code Online (Sandbox Code Playgroud)
这是代码:
using Outlook = Microsoft.Office.Interop.Outlook;
...
private void btnSendEmail_Click(object sender, EventArgs e)
{
try
{
Outlook.Application oApp = new Outlook.Application();
Outlook.MailItem oMsg = Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);
oMsg.HTMLBody = "Hello, here is your message!";
oMsg.Subject = "This is a test message";
Outlook.Recipients oRecips = (Outlook.Recipients)oMsg.Recipients;
Outlook.Recipient oRecip = (Outlook.Recipient)oRecips.Add("rhr@sonlinc.dk");
oRecip.Resolve();
oMsg.Send();
oRecip = null;
oRecips = null;
oMsg = …Run Code Online (Sandbox Code Playgroud) 我已经使用gacutil安装了一个DLL.
gacutil.exe /i SI.ArchiveService.CommonLogic.Exceptions.dll
Run Code Online (Sandbox Code Playgroud)
使用gacutil/l表明它确实安装了.
SI.ArchiveService.CommonLogic.Exceptions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=925c8734ae397609, processorArchitecture=MSIL
Run Code Online (Sandbox Code Playgroud)
然后我想卸载它.
gacutil.exe /u SI.ArchiveService.CommonLogic.Exceptions.dll
Microsoft (R) .NET Global Assembly Cache Utility. Version 3.5.30729.1
Copyright (c) Microsoft Corporation. All rights reserved.
No assemblies found matching: SI.ArchiveService.CommonLogic.Exceptions.dll
Number of assemblies uninstalled = 0
Number of failures = 0
Run Code Online (Sandbox Code Playgroud)
为什么这不起作用?我该如何卸载它?
我的Windows服务写入事件日志,但我遇到了各种问题,这是正确的.所以在这个过程中我使用了许多不同的名字.我跟着一篇文章描述了如何在Windows服务中设置事件日志.因此,在设计器中添加EventLog组件后,我已将其添加到构造函数中:
if (!System.Diagnostics.EventLog.SourceExists("AS0604"))
System.Diagnostics.EventLog.CreateEventSource("AS0604", "SIRR");
eventLog1.Source = "AS0604";
eventLog1.Log = "SIRR";
eventLog1.WriteEntry("AS is initializing...", EventLogEntryType.Information, 16);
Run Code Online (Sandbox Code Playgroud)
我发现,如果源名称与Windows服务的服务名称相同,则会出现问题.但是我一直在为Log和Source更改名称.该
EventLog[] eventLogs = EventLog.GetEventLogs();
Run Code Online (Sandbox Code Playgroud)
列出事件日志,我能够删除那些我没有使用EventLog.Delete命令.
但这是如何工作的?这些已删除的日志中是否仍有已注册的来源?我可以获得注册来源列表吗?
我正在观看有关C#的视频,而这个人使用了一个快捷方式来实现一个属性.
public decimal Price { get; set; }
Run Code Online (Sandbox Code Playgroud)
他不会写整行,而是让visual studio编辑器填写get和set.有谁知道完成上面一行最后一部分的快捷方式?或者更好,像pdf快速参考概述?
我有一个表,每行需要一个时间戳来标记插入的时间.我没有很多数据库经验,但有些东西告诉我,这最好在数据库端自动处理,例如通过存储过程.
在MS SQL中有一个timestamp数据类型,但是阅读它,它被视为一系列数字而不是C#中的DateTime对象.所以如果我不得不进行转换,那么它不能只是一个NVARCHAR数据类型吗?
所以简单地说,当插入到表中时,什么是最简单的方法(自动?)将时间戳放在一行上?
编辑:表定义非常简单.它目前只有两列,但仍缺少时间戳列.
SqlCommand command = con.CreateCommand();
command.CommandText = "INSERT INTO Bio VALUES (" +
"@ID, @Name)";
command.Parameters.AddWithValue("ID",number);
command.Parameters.AddWithValue("Name", name);
try
{
SqlDataReader thisReader = command.ExecuteReader();
thisReader.Close();
}
catch { // Do something };
Run Code Online (Sandbox Code Playgroud)
解决方案好的,它现在有效.我首先尝试通过Visual Studio 2008中的"服务器资源管理器"窗口添加新列.找到我的数据库,右键单击并选择"新建查询".然后键入类似的东西
ALTER TABLE dbo.MyTable ADD CreatedDate datetime NOT NULL DEFAULT (GetUtcDate())
Run Code Online (Sandbox Code Playgroud)
但我收到了消息
不支持ALTER TABLE SQL构造在图和标准窗格中无法以图形方式表示查询.
所以我用图形方式添加了它.首先"打开表定义"并在"数据类型"下的"列名称"和"日期时间"下添加CreatedDate.删除允许空值检查.然后在我添加的列属性中
getutcdate()
Run Code Online (Sandbox Code Playgroud)
在"默认值或绑定"行中的"常规"部分下.每当插入新行时,数据库会自动将当前日期和时间作为时间戳.
有些网站使用websockets.如何检查哪些套接字连接是打开的以及它们打开的端口?
我基本上想浏览一个网站,并能够监视它打开的websocket连接.
我应该使用嗅探器程序,如fiddler,还是可以使用Chrome或Firefox开发人员工具?
c# ×8
event-log ×1
fiddler ×1
firefox ×1
gac ×1
gacutil ×1
outlook-2010 ×1
powershell ×1
sql-server ×1
websocket ×1