小编won*_*nea的帖子

继承类作为函数参数

我有两个类(MyClass1和MyClass2)都继承自MyBaseClass.

我想编写一个函数,将其中任何一个的List作为参数,就像这样

private void DoStuff(List<MyBaseClass> input)

{

...

}
Run Code Online (Sandbox Code Playgroud)

如何将List传递给此函数?

c# generics

1
推荐指数
1
解决办法
55
查看次数

安全地从循环列表中删除列表

我正在遍历主列表中的所有列表,如果出现特定情况.我想删除该特定列表.

它不起作用.

for (int i = 0; i < mainList.Count; i++)
{
     if (mainList[i].Dead == true) //
     {
          mainList.removeAt(i);//what will be affect on mainList.Count;
     }
 }
Run Code Online (Sandbox Code Playgroud)

c# list

1
推荐指数
1
解决办法
3007
查看次数

WebSocket没有连接到socket.io

我使用带有socket.io的Node.js在我的一个页面中实现websockets.server.js(运行Node.js)有这样的代码:

var http = require("http").createServer(),
io = require("socket.io").listen(http);

http.listen(8080);

io.sockets.on("connection", function(socket) {
        socket.emit("message", {hello:"world"});
});
Run Code Online (Sandbox Code Playgroud)

这是我正在尝试连接的代码:

var socket = new WebSocket("ws://92.60.122.235:8080/");
socket.onopen = function() {  
    alert("Socket has been opened!");  
}
Run Code Online (Sandbox Code Playgroud)

当我加载页面时,没有任何反应.我正在使用Chrome,我知道支持websockets.错误控制台中没有错误,如果我从命令行看到socket.io服务请求,我看不到任何用户连接.

据我所知,这应该有效,任何人都可以解释可能出现的问题吗?

javascript websocket node.js socket.io

1
推荐指数
1
解决办法
2459
查看次数

错误org.quartz.plugins.xml.XMLSchedulingDataProcessorPlugin:335 - 错误调度作业:添加了没有触发器的作业必须是持久的

一切似乎与Quartz完美配合,但在启动应用程序时我得到了下面的堆栈跟踪

org.quartz.SchedulerException: Jobs added with no trigger must be durable.
at org.quartz.core.QuartzScheduler.addJob(QuartzScheduler.java:916)
at org.quartz.impl.StdScheduler.addJob(StdScheduler.java:269)
at org.quartz.xml.XMLSchedulingDataProcessor.scheduleJobs(XMLSchedulingDataProcessor.java:1069)
at org.quartz.xml.XMLSchedulingDataProcessor.processFileAndScheduleJobs(XMLSchedulingDataProcessor.java:888)
at org.quartz.plugins.xml.XMLSchedulingDataProcessorPlugin.processFile(XMLSchedulingDataProcessorPlugin.java:330)
at org.quartz.plugins.xml.XMLSchedulingDataProcessorPlugin.start(XMLSchedulingDataProcessorPlugin.java:257)
at org.quartz.plugins.SchedulerPluginWithUserTransactionSupport.start(SchedulerPluginWithUserTransactionSupport.java:144)
at org.quartz.core.QuartzScheduler.startPlugins(QuartzScheduler.java:2343)
at org.quartz.core.QuartzScheduler.start(QuartzScheduler.java:527)
at org.quartz.impl.StdScheduler.start(StdScheduler.java:143)
at org.quartz.ee.servlet.QuartzInitializerServlet.init(QuartzInitializerServlet.java:211)
at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1266)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1185)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1080)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5015)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5302)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:895)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:871)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:615)
at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:958)
at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1599)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
at java.util.concurrent.FutureTask.run(FutureTask.java:166)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:724)
Run Code Online (Sandbox Code Playgroud)

quartz-config.xml中的作业调度似乎很好,所有按计划安排的作业也是如此

知道是什么导致了这个吗?

这是配置文件,对我来说似乎是正确的

<schedule>
    <job>
        <name>ProcessLeadsJob</name>
        <group>PROCESS_LEAD_JOB_GROUP</group>
        <description>This job process the leads every 24 …
Run Code Online (Sandbox Code Playgroud)

quartz-scheduler

1
推荐指数
1
解决办法
9758
查看次数

忽略XML序列化中的属性

我想向从基类派生的实体中添加元素。该实体扩展了基类,该基类没有我可以设置的自定义错误消息。添加元素时,我收到以下警告:

缺少公开可见的类型或成员的XML注释

当我将,[XmlIgnore]但添加到属性,并重新构建包含所有实体的项目时,我仍然收到此消息。因此,仅添加[XmlIgnore]和忘记该消息就足够了吗,还是我需要做其他事情?

在此处输入图片说明

c# xml

1
推荐指数
1
解决办法
282
查看次数

从C#程序连接基于node.js的socket.io WebSocket服务器

我需要从C#windows窗体代码连接基于Node.js的WebSocket

节点模块使用https://github.com/Automattic/socket.io

我正在使用superwebsocket和WebSocket4Net

using SuperSocket.Common;
using SuperSocket.SocketBase;
using SuperSocket.SocketBase.Config;
using SuperSocket.SocketBase.Logging;
using SuperWebSocket;
using SuperWebSocket.SubProtocol;
using WebSocket4Net;

......
......

WebSocket webSocketClient = new WebSocket("ws://localhost:8080/");
webSocketClient.Error += new EventHandler<SuperSocket.ClientEngine.ErrorEventArgs>(webSocketClient_Error);
webSocketClient.AllowUnstrustedCertificate = true;
webSocketClient.Opened += new EventHandler(webSocketClient_Opened);
webSocketClient.Closed += new EventHandler(webSocketClient_Closed);
webSocketClient.MessageReceived += new EventHandler<MessageReceivedEventArgs>(webSocketClient_MessageReceived);
webSocketClient.Open();
Run Code Online (Sandbox Code Playgroud)

但只有webSocketClient_Error回调始终触发,任何人都可以帮忙吗?

c# websocket node.js socket.io websocket4net

1
推荐指数
1
解决办法
2896
查看次数

检查adb设备是否连接状态

如何在批处理文件中检查adb设备是否已连接?我在批处理文件中写了"adb devices",但我希望它作为一个条件,以便应用程序平稳自动地工作.如果用户没有连接,他的设备不打印设备并退出应用程序,否则恢复应用程序.

android cmd batch-file adb

1
推荐指数
2
解决办法
9146
查看次数

是否可以将 UDP 与 Web Sockets 一起使用而不是 TCP

我有一个 C# 桌面应用程序和一个 C# 服务器控制台应用程序。

C# 桌面客户端应用程序使用 WebSocket4Net,而我的 C# 服务器应用程序使用 Fleck。

我假设它使用 TCP 协议是否正确。如果是这样,我可以让它使用UDP协议吗?

我问这个的原因是因为我读取 TCP 比 UDP 慢,因为 TCP 确保数据包的顺序。

我从这篇文章中读到了这个:

制作快节奏的多人网络游戏很难

c# websocket websocket4net

1
推荐指数
1
解决办法
2041
查看次数

如何使用AutoMapper按照类中定义的顺序映射对象?

给定这两个对象(我用一个非常不同的对象来阐明):

public class Car
{
   public string Brand {get;set;}
   public int Speed {get;set;}
}

public class Apple
{
   public string Variety {get;set;}
   public int Production {get;set;}
}
Run Code Online (Sandbox Code Playgroud)

AutoMapper定义projection允许使用不同名称映射属性的:

var config = new MapperConfiguration(cfg =>
        {
            cfg.CreateMap<Car, Apple>()
                 .ForMember(dest => dest.Variety, opt => opt.MapFrom( src => src.Brand))
                 .ForMember(dest => dest.Production, opt => opt.MapFrom(src => src.Speed))
        });
Run Code Online (Sandbox Code Playgroud)

这应该可以,但是:

有什么方法可以按照在类中定义的顺序直接映射属性?

Brand -> Variety
Speed -> Production
Run Code Online (Sandbox Code Playgroud)

我正在使用AutoMapper 4.2.1

.net c# mapping automapper

1
推荐指数
2
解决办法
2653
查看次数

C#将按位运算符作为参数传递

如何将按位运算符作为参数传递给我的方法?我已经阅读了一些文章,这些文章描述了如何将等式运算符作为参数传递,但是它们以某种方式实现它,并在此之后通过委托传递它.在我的情况下,我不知道如何实现按位运算符.

c# bitwise-operators

1
推荐指数
2
解决办法
789
查看次数