我在其他帖子上看到过这个错误,但不是这个确切的情况.
我有两个类使用MessageQueue执行相同的操作.因此,我将队列的创建和处理抽象为helper类.我收到此错误,我无法看到队列如何被多次处理.
对象'messageQueue'可以在方法'MsmqHelper.DisposeQueue(MessageQueue)'中多次处理
在其中一个类中,这是队列的使用方式:
private MessageQueue _messageQueue;
Run Code Online (Sandbox Code Playgroud)
然后,在类的构造函数中:
this._messageQueue = MsmqHelper.InitializeQueue();
Run Code Online (Sandbox Code Playgroud)
这并不重要,但为了完整性,这里是使用队列的地方:
this._messageQueue.Send(workflowCreated);
Run Code Online (Sandbox Code Playgroud)
以下是Dispose方法:
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
private void Dispose(bool disposing)
{
if (disposing == false) { return; }
MsmqHelper.DisposeQueue(this._messageQueue);
}
Run Code Online (Sandbox Code Playgroud)
这是helper类中实际调用Dispose()的代码:
public static void DisposeQueue(MessageQueue messageQueue)
{
if (messageQueue != null)
{
messageQueue.Close();
messageQueue.Dispose();
messageQueue = null;
}
}
Run Code Online (Sandbox Code Playgroud)
在这种情况下,队列可以在哪里被处置多次?
**编辑**
我认为在下面的对话中添加我的评论会很高兴.这是一个很好的总结,以及接受的答案:
我想我现在明白了.messageQueue方法参数与对象的原始(this._messageQueue)引用无关.因此,检查messageQueue为null,并将其设置为null,没有用.即使在被处理之后,调用者仍然可以传入其变量(this._messageQueue).因此,能够不止一次地处置.
顺便说一句,即使在调用方法中将调用者的变量(this._messageQueue)设置为null也无济于事.该问题仅存在于MsmqHelper.DisposeQueue()中.所以答案是通过ref传递或者根本不调用DisposeQueue()并在调用方法中完成所有操作.
**编辑2**
尝试这个后,我得到了同样的错误.我根本就没有得到它.
public static void DisposeQueue(ref MessageQueue messageQueue)
{
if (messageQueue == null) { return; }
messageQueue.Close();
messageQueue.Dispose();
messageQueue = null; …
Run Code Online (Sandbox Code Playgroud) 有人可以解释为RavenDB设置复制的基本步骤吗?我正在使用build 888.从我在网上找到的,我可以猜到可能需要做什么,但我肯定知道.
我相信这是复制的官方文档:http: //ravendb.net/docs/server/bundles/replication
首先,该文件说明:
"可以通过将Raven.Bundles.Replication.dll删除到Raven的插件目录来启用Raven复制."
我在Bundles文件夹中看到了DLL,但是没有Plugins文件夹.我应该创造那个吗?它应该已经存在吗?
看起来我们需要这样做来指定复制服务器:
那是什么?我是否需要将此文档实际保存到数据库中?或者是在某个文件系统的配置文件中?如果我需要将其写入数据库,我是否只是将它放在我的应用程序中并让它第一次运行?每次?
如果这些问题可以得到解答,我可能会有基本的信息来开始.那么也许我可以一步一步地博客作为教程.
我收到第84行和第85行的消息(两个,使用行堆叠):
CA2000:Microsoft.Reliability:在方法'RavenDataAccess.GetRavenDatabase()'中,对象'<> g_ initLocal9'未沿所有异常路径放置.在对对象'<> g _initLocal9'的所有引用都超出范围之前,调用System.IDisposable.Dispose.
DocumentStore实现了IDisposable.
为什么?我还能如何处置DocumentStore对象?它们是在一个使用块中创建的,我将它们放在我的catch块中.该如何修复?
private static IDocumentStore GetRavenDatabase()
{
Shards shards = new Shards();
try
{
using (DocumentStore docStore1 = new DocumentStore { Url = ConfigurationManager.AppSettings["RavenShard1"] }) // Line 84
using (DocumentStore docStore2 = new DocumentStore { Url = ConfigurationManager.AppSettings["RavenShard2"] }) // Line 85
{
shards.Add(docStore1);
shards.Add(docStore2);
}
using (ShardedDocumentStore documentStore = new ShardedDocumentStore(new ShardStrategy(), shards))
{
documentStore.Initialize();
IndexCreation.CreateIndexes(typeof(RavenDataAccess).Assembly, documentStore);
return documentStore;
}
}
catch
{
shards.ForEach(docStore => docStore.Dispose());
throw;
}
}
Run Code Online (Sandbox Code Playgroud) 我有一个带有16个按钮的WPF表单。当我的视图模型初始化时,我需要将全部16个设置为RelayCommand对象。这是我的Initialize()方法所做的全部,但是却导致代码分析错误CA1502:AvoidExcessiveComplexity。
这是抑制CA警告的一个好案例,还是有一种更优雅的方式来设置这些命令而不引起CA违规?
[SuppressMessage("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity", Justification = "Simply setting the commands")]
private void Initialize()
{
this.AddApplicationCommand = new RelayCommand(_ => AddApplication());
this.DeleteApplicationCommand = new RelayCommand(_ => DeleteApplication(), _ => ApplicationIsSelected);
this.RefreshApplicationsCommand = new RelayCommand(_ => RefreshApplications());
this.SaveApplicationCommand = new RelayCommand(_ => SaveApplication(), _ => ApplicationIsSelected);
this.ForceInstallationCommand = new RelayCommand(_ => ForceInstallation(), _ => ApplicationIsSelected);
this.DeleteForceInstallationCommand = new RelayCommand(_ => DeleteForceInstallation(), _ => ApplicationIsSelectedAndForceExists());
this.AddTaskCommand = new RelayCommand(_ => AddTask(), _ => ApplicationIsSelected);
this.EditTaskCommand = new RelayCommand(_ => EditTask(), _ => TaskIsSelected()); …
Run Code Online (Sandbox Code Playgroud) 我正在开发一个WPF应用程序,我只想在任务运行之前和之后更改光标.我有这个代码:
this.Cursor = Cursors.Wait;
Task.Factory.StartNew(() => PerformMigration(legacyTrackerIds)).ContinueWith(_ => this.Cursor = Cursors.Arrow);
Run Code Online (Sandbox Code Playgroud)
光标确实更改为等待光标,但在任务完成时它不会更改回箭头.如果我在ContinueWith()方法中放置一个断点,它就会被击中.但光标不会变回箭头.为什么?
这是我尝试它的旧方法.光标变回箭头,但我不想等待任务的Wait().
this.Cursor = Cursors.Wait;
Task.Factory.StartNew(() => PerformMigration(legacyTrackerIds)).Wait();
this.Cursor = Cursors.Arrow;
Run Code Online (Sandbox Code Playgroud) 我试图让我的toastr 通知显示在 div 的中间。我已经看到了一些建议,比如这个,但它基于整个窗口居中,而不是在一个 div 内。
当 toastr 对表单上的元素一无所知时,是否可以将 Toast 通知置于表单元素中?
我最近的尝试是将 toast 大致居中放置在页面中,但我想将其居中放置在某个 div 中。那可能吗?如果是这样,如何?
这是我的居中尝试:
.toast-center {
top: 50%;
left: 40%;
}
Run Code Online (Sandbox Code Playgroud)
我创建了一个抽象try/catch功能的方法.我有大约30种方法具有完全相同的try/catch方案.所以我把它放在一个方法中:
private T Invoke<T>(Func<T> func)
{
try
{
return func.Invoke();
}
catch (Exception ex)
{
throw LogAndThrowFaultException(ex);
}
}
Run Code Online (Sandbox Code Playgroud)
现在,大多数方法都称之为:
public IEnumerable<PingResponse> GetAllForPingRequest(PingRequest pingRequest)
{
return Invoke(() => PingResponseLogic.GetAllForPingRequest(pingRequest));
}
Run Code Online (Sandbox Code Playgroud)
我的问题是我只有几个方法调用它而不需要返回一个值:
Invoke<void>(() => CustomVariableGroupLogic.Delete(customVariableGroup));
Run Code Online (Sandbox Code Playgroud)
但是,我不能void
在那里使用.该Invoke()
方法需要a func
,但在这种情况下它需要是一个action
.我做了一些研究,看起来我可能需要创建另一种Invoke()
方法,但需要采取行动.这些建议来自2009年和2010年.有可能以某种方式使用我的func方法而不必创建另一种Invoke()
方法Invoke2()
吗?
如果依赖容器或数据访问工厂可以返回可能实现的类型,IDisposable
那么客户是否有责任检查并处理它?在下面的代码中,一个数据类实现IDisposable
而另一个不实现.数据访问工厂可以返回任何一个.
private static void TestPolymorphismWithDisposable()
{
// Here we don't know if we're getting a type that implements IDisposable, so
// if we just do this, then we won't be disposing of our instance.
DataAccessFactory.Resolve().Invoke();
// Do we just have to do something like this?
IFoo foo = DataAccessFactory.Resolve();
foo.Invoke();
var fooAsDisposable = foo as IDisposable;
if (fooAsDisposable != null) { fooAsDisposable.Dispose(); }
}
Run Code Online (Sandbox Code Playgroud)
我问的原因是,这似乎给客户端代码带来了负担,必须处理这个问题,在构建API时,如何让客户知道他们可能需要调用dispose?是否有更好的方法来处理客户端无需检查的情况IDisposable
?
为了完整的工作示例,以下是其他类:
public interface IFoo
{ …
Run Code Online (Sandbox Code Playgroud) 我想显示查询的结果,并且我想同时捕获列的值。该FROM
和WHERE
是在这两个查询相同。我可以在一个查询中同时执行两个查询,还是只执行两次查询更容易/更好?
DECLARE @fooId INT
SET @fooId = (SELECT FooId FROM Bar WHERE SnuhId = 5)
SELECT * FROM Bar WHERE SnuhId = 5
Run Code Online (Sandbox Code Playgroud) 编辑/摘要
经过大量的反复试验,Paul Kearney-pk帮助我找到答案,虽然我仍然不知道为什么会这样,至少我知道如何让它发挥作用.
快速摘要:当我在工作时直接连接到我的网络时,客户端可以连接到笔记本电脑上的端口8080.当我在家庭网络上时,客户端无法连接到端口8080.为了解决这个问题,我创建了一个防火墙规则(在我的笔记本电脑上)以允许8080上的入站流量.我真的想知道为什么会这样.我的笔记本电脑的Windows防火墙服务是否真的根据我连接的网络更改其设置?
注意:当我在网络上工作时,这一切都有效,但它不能在我的家庭网络或其他人的家庭网络上运行.主机(我的笔记本电脑)在两个位置都是相同的.
我有一个使用SignalR的网络应用程序.当我在运行SignalR主机的同一台机器上运行Web应用程序时,一切正常.当我尝试从另一台机器连接时,我收到此错误:
> GET http://10.0.0.13:8080/signalr/hubs net::ERR_CONNECTION_TIMED_OUT. Cannot read property 'client' of undefined.
Run Code Online (Sandbox Code Playgroud)
该错误来自我的index.html页面:
<script src="http://10.0.0.13:8080/signalr/hubs"></script>
Run Code Online (Sandbox Code Playgroud)
根据我所做的研究,我知道我不应该localhost
在我的SignalR URL中使用.所以我使用了星号.这是我自己托管的SignalR应用程序:
class Program
{
static void Main(string[] args)
{
string url = "http://*:8080";
using (WebApp.Start(url))
{
Console.WriteLine("Server running on {0}", url);
Console.ReadLine();
}
}
}
class Startup
{
public void Configuration(IAppBuilder app)
{
app.UseCors(CorsOptions.AllowAll);
app.MapSignalR();
}
}
public class RaceHub : Hub
{
public void Send(string name, string message)
{
Clients.All.addMessage(name, message);
} …
Run Code Online (Sandbox Code Playgroud) c# ×7
asp.net ×2
dispose ×2
idisposable ×2
ravendb ×2
action ×1
ca2000 ×1
css ×1
func ×1
javascript ×1
networking ×1
polymorphism ×1
replication ×1
signalr ×1
sql ×1
sql-server ×1
t-sql ×1
task ×1
toastr ×1