- संपादित करें आपका ऐप्लिकेशन किसी "विंडोज आवेदन" (नहीं "कंसोल एप्लिकेशन") बनाने के लिए अपनी परियोजना के गुण। आप अभी भी कमांड लाइन पैरामीटर स्वीकार कर सकते हैं। यदि आप ऐसा नहीं करते हैं, तो जब आप ऐप के आइकन पर डबल-क्लिक करते हैं तो एक कंसोल विंडो पॉप अप हो जाएगी।
- सुनिश्चित करें कि आपका
Main
फ़ंक्शन कमांड लाइन पैरामीटर स्वीकार करता है।
- यदि आपको कोई कमांड लाइन पैरामीटर मिलता है तो विंडो न दिखाएं।
[STAThread]
static void Main(string[] args)
{
if(args.Length == 0)
{
Application.Run(new MyMainForm());
}
else
{
// Do command line/silent logic here...
}
}
अपने एप्लिकेशन पहले से ही संरचित नहीं है, तो करने के लिए सफाई से कर चुप प्रसंस्करण (यदि आपके सभी तर्क अपने WinForm कोड में जाम है), आप कर सकते हैं hack silent processing in ala CharithJ's answer:
यहाँ एक छोटी उदाहरण है।
ओपी द्वारा संपादित करें अपने उत्तर Merlyn को हाइजैक करने के लिए खेद है। बस दूसरों के लिए सभी जानकारी चाहते हैं।
एक WinForms अनुप्रयोग में सांत्वना देने लिखने के लिए सक्षम होने के लिए सिर्फ निम्न कार्य करें:
static class Program
{
// defines for commandline output
[DllImport("kernel32.dll")]
static extern bool AttachConsole(int dwProcessId);
private const int ATTACH_PARENT_PROCESS = -1;
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
// redirect console output to parent process;
// must be before any calls to Console.WriteLine()
AttachConsole(ATTACH_PARENT_PROCESS);
if (args.Length > 0)
{
Console.WriteLine("Yay! I have just created a commandline tool.");
// sending the enter key is not really needed, but otherwise the user thinks the app is still running by looking at the commandline. The enter key takes care of displaying the prompt again.
System.Windows.Forms.SendKeys.SendWait("{ENTER}");
Application.Exit();
}
else
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new QrCodeSampleApp());
}
}
}
स्रोत
2011-08-26 01:07:36
आप पूरी तरह एक ही आवेदन का उपयोग कर सकते हैं। बस अपनी मुख्य विधि –
पर 'स्ट्रिंग [] args' जोड़ें या, इस प्रश्न के उत्तर देखें: http://stackoverflow.com/questions/1179532/ –
चूंकि आप कंसोल से इनपुट पढ़ने के बारे में नहीं पूछ रहे हैं (केवल कमांड लाइन पैरामीटर से), यह एक डुप्ली है। –