I have two project one is windows form Assembly name "project_1" and the second project is consol project name "project_2" I used multiple startup project to run both and make "project_2" initialized, my question is there is any way to makes the "project_2" run when press button from project one???
答案 0 :(得分:0)
我已经为表单应用程序和控制台应用程序提供了代码。
using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
AllocConsole();
}
private void button1_Click(object sender, EventArgs e)
{
ConsoleApplication.Program.Main(new string[] {});
}
[DllImport("kernel32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool AllocConsole();
}
必须添加DllImport才能访问非托管代码。
public class Program
{
public static void Main(string[] args)
{
using (var writer =
new StreamWriter(@"C:\Users\Farttoos\Desktop\Nasser_Last\Crypto(AES)_Stego(text)_Final\Crypto_Stego\Dictionary.txt"))
{
Console.SetOut(writer);
Console.Write("Hello World!");
Act();
}
}
}