MessageBox in app started from command line

G

Guest

Hi,
I'm trying to add a couple of command line switches to a windows forms
application which will perform a short operation and possibly display a
message box to the user then immediately exit.
It works fine when I run from the debugger but if I run the app from a cmd
window the messageboxes show up with no text on the form or the ok button.

This simple application shows what I mean. If I run this from the VS
debugger it behaves as I would expect, but if I run it directly from a cmd
prompt I get blank message boxes.
(this is in VS 2005 with .net 2.0 btw)

using System;
using System.Collections.Generic;
using System.Windows.Forms;

namespace WindowsApplication2
{
static class Program
{
[STAThread]
static void Main( string[] args )
{
foreach (string arg in args)
{
MessageBox.Show(arg);
}

}
}
}
 
J

John Kn [MS]

I had difficulties getting your code to build. VS did not like the 'static'
lable. Pare down the following code to fit your needs.
The following works for me in debug and if I copying the .exe and the .pdb
to a remote machine:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace WindowsApplication7
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;

public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();

//
// TODO: Add any constructor code after InitializeComponent call
//
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.Size = new System.Drawing.Size(300,300);
this.Text = "Form1";
}
#endregion

/// <summary>
/// The main entry point for the application.
/// </summary>
class Program
{
[STAThread]
static void Main( string[] args )
{
foreach (string arg in args)
{
MessageBox.Show(arg);
}

}
}

}
}

Thanks

--------------------
Thread-Topic: MessageBox in app started from command line
thread-index: AcVl69bKz9Eae6AiQqCTGK944xOMGA==
X-WBNR-Posting-Host: 57.67.17.3
From: "=?Utf-8?B?TWVyaXQ=?=" <[email protected]>
Subject: MessageBox in app started from command line
Date: Tue, 31 May 2005 07:20:04 -0700
Lines: 31
Message-ID: <[email protected]>
MIME-Version: 1.0
Content-Type: text/plain;
charset="Utf-8"
Content-Transfer-Encoding: 7bit
X-Newsreader: Microsoft CDO for Windows 2000
Content-Class: urn:content-classes:message
Importance: normal
Priority: normal
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
Newsgroups: microsoft.public.dotnet.framework.windowsforms
NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250
Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGXA03.phx.gbl
Xref: TK2MSFTNGXA01.phx.gbl microsoft.public.dotnet.framework.windowsforms:21201
X-Tomcat-NG: microsoft.public.dotnet.framework.windowsforms

Hi,
I'm trying to add a couple of command line switches to a windows forms
application which will perform a short operation and possibly display a
message box to the user then immediately exit.
It works fine when I run from the debugger but if I run the app from a cmd
window the messageboxes show up with no text on the form or the ok button.

This simple application shows what I mean. If I run this from the VS
debugger it behaves as I would expect, but if I run it directly from a cmd
prompt I get blank message boxes.
(this is in VS 2005 with .net 2.0 btw)

using System;
using System.Collections.Generic;
using System.Windows.Forms;

namespace WindowsApplication2
{
static class Program
{
[STAThread]
static void Main( string[] args )
{
foreach (string arg in args)
{
MessageBox.Show(arg);
}

}
}
}

{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fnil\fprq2\fcharset0
MS Sans Serif;}{\f1\fswiss\fcharset0 Arial;}}
{\*\generator Msftedit 5.41.21.2500;}\viewkind4\uc1\pard\f0\fs20 Cheers,\par
\par
johnKn [MS-SDK]\par
\par
\par
\par
-Please do not send email directly to this alias. This alias is for \par
newsgroup purposes only\par
\par
-This posting is provided "AS IS" with no warranties, and confers no
rights.\par
\par
-To provide additional feedback about your community experience please send
\par
e-mail to: (e-mail address removed)\par
\f1\par
}
 
M

Merit

Testing on a different machine (without VS installed) with your code or
mine gives me the expected (correct) behavior. My personal machine has
a good bit of bleeding edge beta code on it, so I guess that something
is causing this strange result. Since it appears to usually work I'm
not going to worry about it.
Thanks for your time.
-Merit
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top