重新访问单实例应用程序

重新访问单实例应用程序

问题描述:

前段时间我需要编写一个单实例应用程序。这是一个简单的任务

但我还需要重复的实例来将他们的命令行参数

传递给第一个实例,以便它可以对它们采取行动。


我最终使用Remoting来启动我的第一个应用程序,然后

调用来自辅助实例的Singleton远程对象。我想

我很聪明直到今天我试图展示一个OpenFileDialog并且

收到错误告诉我必须使用我的应用程序的主线程。 br />

它被证明是一个真正的痛苦:-)有没有人有他们的解决方案

尝试过?


Pete

Some time ago I needed to write a single-instance app. That''s an easy task
but I also needed duplicate instances to pass their command line parameters
to the first instance so that it can act upon them.

I ended up achieving this using Remoting to start my first app, and then
call into that Singleton remoted object from secondary instances. I thought
I was pretty clever until today when I tried to show an OpenFileDialog and
received an error telling me I have to use my app''s main thread.

It''s proving to be a real pain :-) Does anyone have a solution they have
tried?

Pete

2008年9月25日星期四11:58:02 -0700,Peter Morris

< mr ********* @ spamgmail.comwrote:
On Thu, 25 Sep 2008 11:58:02 -0700, Peter Morris
<mr*********@spamgmail.comwrote:

前段时间我需要编写一个单实例应用程序。这是一个简单的

任务,但我还需要重复的实例来将他们的命令行

参数传递给第一个实例,以便它可以对它们采取行动。


我最终使用Remoting来启动我的第一个应用程序,然后

调用来自辅助实例的Singleton远程对象。我认为我很聪明直到今天我试图展示一个

OpenFileDialog并收到错误告诉我必须使用我的应用程序

主线程。 [...]
Some time ago I needed to write a single-instance app. That''s an easy
task but I also needed duplicate instances to pass their command line
parameters to the first instance so that it can act upon them.

I ended up achieving this using Remoting to start my first app, and then
call into that Singleton remoted object from secondary instances. I
thought I was pretty clever until today when I tried to show an
OpenFileDialog and received an error telling me I have to use my app''s
main thread. [...]



真的吗?这让我感到惊讶。当然,我还没有尝试过,大概是b $ b,重现这种行为对我来说是微不足道的。但是对话框,他们自己的消息循环,通常可以在任意线程上正常工作。


那说,鉴于这个要求,为什么不是标准技术

适用?也就是说,只需使用Control.Invoke()或类似代码来执行代码

来显示正确线程上的对话框?


Pete

Really? That surprises me. Granted, I haven''t tried it, and presumably
it''d be trivial for me to reproduce the behavior. But dialogs, having
their own message loops, usually work okay on any arbitrary thread.

That said, given that requirement, why doesn''t the standard technique
apply? That is, just use Control.Invoke() or similar to execute the code
to show the dialog on the correct thread?

Pete


Peter Morris< mr ********* @ SPAMgmail.comwrote:
Peter Morris <mr*********@SPAMgmail.comwrote:

前段时间我需要编写单实例应用程序。这是一个简单的任务

但我还需要重复的实例来将他们的命令行参数

传递给第一个实例,以便它可以对它们采取行动。


我最终使用Remoting来启动我的第一个应用程序,然后

调用来自辅助实例的Singleton远程对象。我想

我很聪明直到今天我试图展示一个OpenFileDialog并且

收到错误告诉我必须使用我的应用程序的主线程。 br />

它被证明是一个真正的痛苦:-)有没有人有他们的解决方案

尝试?
Some time ago I needed to write a single-instance app. That''s an easy task
but I also needed duplicate instances to pass their command line parameters
to the first instance so that it can act upon them.

I ended up achieving this using Remoting to start my first app, and then
call into that Singleton remoted object from secondary instances. I thought
I was pretty clever until today when I tried to show an OpenFileDialog and
received an error telling me I have to use my app''s main thread.

It''s proving to be a real pain :-) Does anyone have a solution they have
tried?



您是否尝试过使用Microsoft.VisualBasic.ApplicationServices

课程?


阅读 http://msdn.microsoft.com/ en-us / libr ... wx(VS.80).aspx 和

看看它是否对你有帮助。就个人而言,我认为在System中拥有这种

类功能会很不错。* ...


-

Jon Skeet - < sk *** @ pobox.com>

网站: http://www.pobox.com/~skeet

博客: http://www.msmvps.com/jon.skeet

C#深度: http://csharpindepth.com

Have you tried using the Microsoft.VisualBasic.ApplicationServices
classes?

Read http://msdn.microsoft.com/en-us/libr...wx(VS.80).aspx and
see if it helps you. Personally I think it would be nice to have this
sort of functionality in System.*...

--
Jon Skeet - <sk***@pobox.com>
Web site: http://www.pobox.com/~skeet
Blog: http://www.msmvps.com/jon.skeet
C# in Depth: http://csharpindepth.com


是的。不幸的是,它抛出了NotImplemented。或NotSupported或NotSupported例外

(不记得是哪一个)在几台工作机器上,所以我放弃了它。
Yes. Unfortunately it threw a "NotImplemented" or "NotSupported" exception
(don''t recall which) on a couple of machines at work, so I abandoned it.