重新访问单实例应用程序

编程入门 行业动态 更新时间:2024-10-19 20:36:13
本文介绍了重新访问单实例应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

前段时间我需要编写一个单实例应用程序。这是一个简单的任务 但我还需要重复的实例来将他们的命令行参数 传递给第一个实例,以便它可以对它们采取行动。 我最终使用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 ********* @ spamgmailwrote: On Thu, 25 Sep 2008 11:58:02 -0700, Peter Morris <mr*********@spamgmailwrote: 前段时间我需要编写一个单实例应用程序。这是一个简单的 任务,但我还需要重复的实例来将他们的命令行 参数传递给第一个实例,以便它可以对它们采取行动。 我最终使用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 ********* @ SPAMgmailwrote: Peter Morris <mr*********@SPAMgmailwrote: 前段时间我需要编写单实例应用程序。这是一个简单的任务 但我还需要重复的实例来将他们的命令行参数 传递给第一个实例,以便它可以对它们采取行动。 我最终使用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 课程? 阅读 msdn.microsoft/ en-us / libr ... wx(VS.80).aspx 和 看看它是否对你有帮助。就个人而言,我认为在System中拥有这种 类功能会很不错。* ... - Jon Skeet - < sk *** @ pobox> 网站: www.pobox/~skeet 博客: www.msmvps/jon.skeet C#深度: csharpindepth

Have you tried using the Microsoft.VisualBasic.ApplicationServices classes? Read msdn.microsoft/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> Web site: www.pobox/~skeet Blog: www.msmvps/jon.skeet C# in Depth: csharpindepth

是的。不幸的是,它抛出了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.

更多推荐

重新访问单实例应用程序

本文发布于:2023-11-16 14:31:13,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1605137.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:应用程序   实例

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!