AIRアプリを自動更新して再起動させたい事があったのでそのときに書いたコードを紹介します。
AIRアプリからC#アプリを起動し、AIRアプリは終了。起動したC#アプリは1秒待ってから再度AIRアプリを起動させるという流れのコードです。
AIR -> C#の起動、C# -> AIRの起動はできたんですがAIR -> C# -> AIRで起動させようとすると何故か最後のAIRアプリの起動できなかったので少しまどろっこしい方法にしています。(AIR20.0 for Desktopになってから外部アプリ起動の仕様が変わった(?))
今回AIRアプリ再起動としてC#アプリを起動させていますが、UnityやopenFrameworksのアプリの再起動にも使えます。(※winに限ります。)
ActionScript
info.arguments = arguments1; でC#側にAIRアプリのパスを渡しています。
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | function NewAppRun(){ 	var newExeFile:File = new File(File.applicationDirectory.resolvePath("RunNewApp.exe").nativePath); 	if ( newExeFile.exists ){ 		// 新しいアプリを起動して 		var info:NativeProcessStartupInfo = new NativeProcessStartupInfo(); 		var arguments1:Vector.<String> = new Vector.<String>(); 		arguments1[0] = File.applicationDirectory.nativePath + "\\AirApp.exe"; 		info.arguments = arguments1; 		info.executable = newExeFile; 		var process:NativeProcess = new NativeProcess(); 		process.start(info); 		// 現在のアプリは終了 		thisApp.exit(0); 	}else{ 		trace("!newExeFile.exists"); 	} } | 
C#
Consoleアプリです。1秒待ってからAIRアプリ側から受け取ったパスのアプリを起動します。こちらGitにプロジェクトファイルをアップしておきました。
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | using System; using System.Collections.Generic; using System.Threading.Tasks; namespace PortableDevices {     class Program     {         static void Main(string[] args)         {             Console.WriteLine("RUN NEW APP");             System.Threading.Thread.Sleep(1000);             System.Diagnostics.Process process = new System.Diagnostics.Process();             process.StartInfo.FileName = args[0];             process.Start();         }     } } | 
 
		         
							
														
						 
							
														
						




 
					
				


コメントを残す