[C#] winForm執行另一個WPF程序並得到回傳值

我的範例 : WinForm端 (Parent)

呼叫 RunWPF() 就會去執行叫起 WPF process
如下程式碼

106 private void RunWPF()\r
107 {\r
108 Task.Run(() => RunWPFProcess());\r
109 }\r
110 \r
111 private void RunWPFProcess()\r
112 {\r
113 int ReturnValue = -1;\r
114 Process process = new Process();\r
115 process.StartInfo.FileName = “myWPF.exe“;\r
116 \r
117 try\r
118 {\r
119 process.Start();\r
122 process.WaitForExit(Int32.MaxValue);\r
123 ReturnValue = process.ExitCode;\r
124 }\r
125 catch (System.Exception ex)\r
126 {\r
127 }\r
128 \r
129 if (ReturnValue == 1)\r
130 {\r
131 /* You can do what you want as return value is 1 */ \r
137 }\r
138 else \r
139 {\r
140 /* You can do what you want as others */ \r
146 }\r
147 }\r

另一端WPF部分: (Child)

myWPF.exe 裡面程式碼,
這裡我就直接寫出如何傳值回去給winform程序
其他一概省略..

227 Environment.ExitCode = 1;\r
228 this.Close();\r

發表迴響

Copy Protected by Chetan's WP-Copyprotect.