我需要动态设置对象上的值或属性的值,称之为传输对象.
将会创建相当数量的这些传输对象,并在短时间内设置其属性.我想避免使用反射.
还有替代品吗?如果是这样的样本实现我可以看一下?
什么是监控队列的最有效方法.
以下代码是最大的资源:
/// <summary>
/// Starts the service.
/// </summary>
private void StartService()
{
while (true)
{
//the check on count is not thread safe
while (_MessageQueue.Count > 0)
{
Common.IMessage message;
// the call to GetMessageFromQueue is thread safe
if (_MessageQueue.GetMessageFromQueue(out message) == true)
{
if (message.RoutingInfo == Devices.Common.MessageRoutingInfo.ToDevice)
{
_Port.SerialPort.WriteLine(message.Message);
}
if (message.RoutingInfo == Devices.Common.MessageRoutingInfo.FromDevice)
{
OnDeviceMessageReceived(new Common.DeviceMessageArgs(message.Message));
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
Start Service在后台线程上运行,对_MessageQueue.Count的调用不是线程安全的,我没有锁定MessageQueue中的count.但是我确实锁定了_MessageQueue.GetMessageFromQueue的实现.我这样做有效吗?我是否应该提高事件每次队列从0到大于0?
任何人都可以想到在winforms应用程序中不使用ASP.NET成员资格提供程序的原因吗?
有没有人有这方面的经验?