我以前使用过BeginAccept()和BeginRead(),但与Visual Studio 2012我想利用新的异步的(async,await)功能在我的socket服务器程序.
我该如何完成AcceptAsync和ReceiveAsync功能?
using System.Net;
using System.Net.Sockets;
namespace OfficialServer.Core.Server
{
public abstract class CoreServer
{
private const int ListenLength = 500;
private const int ReceiveTimeOut = 30000;
private const int SendTimeOut = 30000;
private readonly Socket _socket;
protected CoreServer(int port, string ip = "0.0.0.0")
{
_socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
_socket.Bind(new IPEndPoint(IPAddress.Parse(ip), port));
_socket.Listen(ListenLength);
_socket.ReceiveTimeout = ReceiveTimeOut;
_socket.SendTimeout = SendTimeOut;
_socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.KeepAlive, true);
_socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.DontLinger, true); …Run Code Online (Sandbox Code Playgroud) 我正在尝试创建一个将常规sql语句转换为c#对象的方法,所以我决定使用Irony来解析sql语句然后我将该语句作为Action返回,其中包含语句的类型及其值取决于类型
这是我未完成的代码[因为我感到沮丧因为我不知道该怎么办]
private List<Action> ParseStatement(string statement)
{
var parser = new Parser(new SqlGrammar());
var parsed = parser.Parse(statement);
var status = parsed.Status;
while (parsed.Status == ParseTreeStatus.Parsing)
{
Task.Yield();
}
if (status == ParseTreeStatus.Error)
throw new ArgumentException("The statement cannot be parsed.");
ParseTreeNode parsedStmt = parsed.Root.ChildNodes[0];
switch (parsedStmt.Term.Name)
{
case "insertStmt":
var table = parsedStmt.ChildNodes.Find(x => x.Term.Name == "Id").ChildNodes[0].Token.ValueString;
var valuesCount =
parsedStmt.ChildNodes.Find(x => x.Term.Name == "insertData").ChildNodes.Find(
x => x.Term.Name == "exprList").ChildNodes.Count;
var values = parsedStmt.ChildNodes.Find(x => x.Term.Name == "insertData").ChildNodes.Find(
x => x.Term.Name …Run Code Online (Sandbox Code Playgroud) 我刚刚升级到VS2017但是刚刚开始我的项目无法构建,因为我在使用VS15时遇到了一堆奇怪的编译器错误.
错误如:
Syntax Error; value expectedInvalid Expression Term '['Invalid Expression Term 'byte'Using the generic type requires 1 type argumentsusing System;
using System.Runtime.InteropServices;
namespace Error
{
class Program
{
static void Main()
{
Array array2D = null;
if (array2D is Bgra <byte>[,])
{
}
}
}
public interface IColor { }
public interface IColor<T> : IColor
where T : struct
{ }
public interface IColor2 : IColor { }
public interface IColor2<T> : IColor2, IColor<T> …Run Code Online (Sandbox Code Playgroud) 正如标题所述,我想知道使用这样的类之间的区别
public class Account
{
public string Username { get; set; }
public string Password { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
并使用和接口这样
public class Account : IAccount
{
public string Username { get; set; }
public string Password { get; set; }
}
public interface IAccount
{
string Username { get; set; }
string Password { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我真的很困惑,因为我发现接口是无用的,因为我可以用它做的只能使用Class,因此,我需要有人为我澄清一些事情.
好吧,我有一个Windows窗体应用程序,其中我添加了几个listViews,以便为用户保存一些数据,它看起来像这样

当你看到我的表格背景颜色为黑色时,列表视图的网格线和标题白色会产生令人讨厌的对比,所以经过一个小时的搜索没有运气我决定在这里问.
[问题]:如何编辑列表视图的页眉和网格线的颜色以满足我的需求?
当我在Release模式下构建我的应用程序时,我的文件夹充斥着 .xml 文件,无论如何要阻止它?
在我的情况下,我想将自定义 .net 程序集加载到正在运行的 .net 进程的域中,例如Windows Explorer,我已经尝试过的只是将程序集注入其中,explorer.exe但这似乎没有明显原因。
喷油器代码:
public class CodeInjector
{
[DllImport("kernel32.dll", SetLastError = true)]
public static extern IntPtr OpenProcess(uint dwDesiredAccess, int bInheritHandle, uint dwProcessId);
[DllImport("kernel32.dll", SetLastError = true)]
public static extern int CloseHandle(IntPtr hObject);
[DllImport("kernel32.dll", SetLastError = true)]
public static extern IntPtr GetProcAddress(IntPtr hModule, string lpProcName);
[DllImport("kernel32.dll", SetLastError = true)]
public static extern IntPtr GetModuleHandle(string lpModuleName);
[DllImport("kernel32.dll", SetLastError = true)]
public static extern IntPtr VirtualAllocEx(IntPtr hProcess, IntPtr lpAddress, IntPtr dwSize, uint flAllocationType, uint flProtect);
[DllImport("kernel32.dll", …Run Code Online (Sandbox Code Playgroud) 我试图在窗体上的某些按钮之间创建某种联系,这样当我单击一个按钮时,它会突出显示所有以前的按钮[某种音量控制器]

想象一下它是一个音量控制器.所有这些彩色按钮都是灰色的,我想要实现的是当你点击一个按钮时,它会将所有按钮着色; 然而IDK在不涉及大量无用代码的情况下制作这样的行为的最佳方式是什么...
我试图清理使用后生成事件,所以我删除了发行文件夹.xml和.pdb文件,并尝试将所有的dll文件复制到定制lib文件夹中的错误,我得到Post Build Exited with Code 1
我的代码:
if $(ConfigurationName) == Release del "$(TargetDir)*.xml", "$(TargetDir)*.pdb"
if $(ConfigurationName) == Release xcopy "$(TargetDir)\*.dll" "$(TargetDir)\lib\"
Run Code Online (Sandbox Code Playgroud)
如图所示,2个命令由新行分隔...还存在Lib文件夹.
在我的Asp.Net Razor应用程序中,我不断获得断点当前不会被击中我已经尝试了每一个解决方案,这里断点当前不会被击中没有符号加载没有运气.那我接下来该怎么办?
一些信息:
这是我的web.config
<?xml version="1.0" encoding="utf-8"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<configSections>
<sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
</sectionGroup>
</configSections>
<!--
For a description of web.config changes see http://go.microsoft.com/fwlink/?LinkId=235367.
The following attributes can be set on the <httpRuntime> tag.
<system.Web>
<httpRuntime targetFramework="4.5.1" />
</system.Web> …Run Code Online (Sandbox Code Playgroud)