Jür*_*ock 6 .net c# vb.net clickonce winforms
我已经部署了ClickOnce Windows窗体应用程序(App A)
另一个应用程序(App B)以文件名作为参数启动App A. 我使用此代码执行此操作
var basePath = Environment.GetFolderPath(Environment.SpecialFolder.Programs);
var location = String.Format(@"{0}\{1}\{2}\{3}",
basePath, "MyCompany", "MyProduct", "MyApp.appref-ms");
var fileName = @"c:\temp\somefile.ext";
var uri = new Uri(fileName).ToString();
Process.Start(location, uri);
Run Code Online (Sandbox Code Playgroud)
应用程序A从中获取文件名AppDomain.CurrentDomain.SetupInformation.ActivationArguments.ActivationData[0]
并显示内容.
这就像一个魅力.但是,现在我希望App B等待App A退出.但是要求Process.WaitForExit()
立即回报.
有没有办法打开ClickOnce应用程序并等待它退出?我可以,如果有必要,改变应用程序的运行方式,但要求是我需要将应用程序作为ClickOnce应用程序运行(我知道在我的用户配置AppData\Local\Apps\2.0\
文件文件夹中的某个地方存在exe并且可以直接启动但是如果我这样做的话那ApplicationDeployment.IsNetworkDeployed
是false
和ApplicationDeployment.CurrentDeployment
null.因为我放松了ClickOnce更新功能).
我的建议是在App A中使用Mutex,并让App B检查并等待它。从我的角度来看,这是最干净的方式。
应用程序 A 在启动时执行此操作:
private static Mutex mutex;
public static void Main()
{
// if you want your app to be limited to a single instance
// across ALL SESSIONS (multiple users & terminal services), then use the following line instead:
// string mutexName = string.Format("Global\\{0}", ProgramInfo.AssemblyGuid);
var mutexName = string.Format("Local\\{0}", SOME_SHARED_GUID);
mutex = new Mutex(true, mutexName, out singleInstance);
if (singleInstance == false)
{
// that means your app has more than one instance running
// you need to decide what to do here.
}
// rest of initialization code
Application.Run();
// release the mutex so App B can continue
mutex.ReleaseMutex();
}
Run Code Online (Sandbox Code Playgroud)
App B 只是等待互斥体被释放:
Process.Start(location, uri);
Thread.Sleep(5000); // give it 5 seconds or so to check for updates and start
var mutexName = string.Format("Local\\{0}", SOME_SHARED_GUID);
mutex = new Mutex(false, mutexName);
mutex.WaitOne();
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1962 次 |
最近记录: |