Reputation: 10566
I have an C# application with Windows Forms output type. It works fine when I launch it from bin/Debug or bin/Release folders (I use Visual Studio Express 2008 to develop it). But when I copied that app from Release folder to another, then I start it, something strange happening. Sometimes it loads too long (before window shows), and even when it loads, the text area located on Group box is not visible!
I don't know why it is happening, but I want to try to see what happening during app load. Is there any way to know what happening during C# Windows Forms application start?
Update: I found out that TextArea disappear and application loads with some delay because I redirect console output to that text area:
public class TextBoxStreamWriter : TextWriter
{
TextBox _output = null;
delegate void SetTextCallback(char value);
public TextBoxStreamWriter(TextBox output)
{
_output = output;
}
public override void Write(char value)
{
if (MainForm.closed)
return;
base.Write(value);
if (_output.InvokeRequired)
{
SetTextCallback d = new SetTextCallback(Write);
_output.Invoke(d, new object[] { value });
}
else
{
_output.AppendText(value.ToString());
}
}
public override Encoding Encoding
{
get { return System.Text.Encoding.UTF8; }
}
}
And if I comment those two lines, it works!:
//_writer = new TextBoxStreamWriter(logTextArea);
//Console.SetOut(_writer);
But I still don't understand why!
Upvotes: 1
Views: 169
Reputation: 1442
Before the line that throws the error, put this code:
System.Diagnostics.Debugger.Launch()
Run your code from where you get the exception, when it hit this line it will give you a chance to attach the process to the Debugger.
Upvotes: 3
Reputation: 1525
If you're fast enough, you could launch the application from the location it malfunctions from, switch to VS, go to Debug -> Attach to Process. Find the process in the list, attach to it real quick, then press the pause button and start stepping through the code.
It may take some practice, but I can normally do it fairly quickly.
Upvotes: 1
Reputation: 25619
Is it YOUR application? there might be some configuration settings in the .config files of the Application, such as, for example, a setting that indicates whether to display the Text in the TextBox or not.
Copy the .config files along with the .exe and see what happens.
EDIT:
You can use Process Monitor from SysInternals to monitor the actions of the application
Both are excellent tools for monitoring\debugging applications.
Upvotes: 1