473,396 Members | 1,872 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Why Won't This Console App Do A Console.WriteLine() ?

This is driving me crazy.

I finally got the Remoting sample chat application working almost.

When I run the chat client in VS.NET it goes into an endless loop --
that's because I assume that there is now way for me to interface to a
Console.ReadLine().

However, when I run it in the cmd window, it does not output any
Console.WriteLine()s ( even the "Hello" that I put as the first
statement in Main() ). Nothing prints to the command line!?!

ChatClient.exe definitely loads and is 'running' because I see it in
Task Manager! I can even run as many instances as I want...but none
are printing to the command line.

How can it just skip doing the Console.WriteLine() ???

Here is the code:

// ChatClient.cs
using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Http;

public class ChatClient
{

private string _alias = null;

public ChatClient(string alias)
{
this._alias = alias;
}

public void Run()
{
RemotingConfiguration.Configure("ChatClient.exe.co nfig");

// Create a proxy to the remote object.
ChatCenter chatcenter = new ChatCenter();

// Create a remotely delegatable object
MyCallbackClass callback = new MyCallbackClass (_alias) ;

// Create a new delegate for the method that you want the event to call
// when it occurs on the server. The SubmissionReceiver method will
// then be a remote call for the server object; therefore, you must
// register a channel to listen for this call back from the server.
chatcenter.Submission += new
SubmissionEventHandler(callback.SubmissionCallback );
String keyState = "";

while (true)
{
Console.WriteLine("Press 0 (zero) and ENTER to Exit:\r\n");
keyState = Console.ReadLine();
if (String.Compare(keyState,"0", true) == 0)
break;
// Call the server with the string you submitted and your alias.
chatcenter.Submit(keyState, _alias);
}
chatcenter.Submission -= new
SubmissionEventHandler(callback.SubmissionCallback );
}
// Args[0] is the alias that will be used.
public static void Main(string[] Args)
{

//this hello does not print
Console.WriteLine("hello");

if (Args.Length != 1)
{
Console.WriteLine("You need to type an alias.");
return;
}
else
{
Console.WriteLine("running...");
}

ChatClient client = new ChatClient(Args[0]);
//= new ChatClient("john");
client.Run();
}
}

// MyCallbackClass is the class that contains the callback function to
// which ChatClient will submit a delegate to the server.
// To to pass a reference to this method (that is, a delegate)
// across an application domain boundary, this class must extend
// MarshalByRefObject or a class that extends MarshallByRefObject like all
// other remotable types. MyCallbackClass extends
RemotelyDelegatableObject because
// RemotelyDelegatableObject is a class that the server can obtain type
information
// for.
class MyCallbackClass : RemotelyDelegatableObject
{
private string _alias = null;

public MyCallbackClass () {}
public MyCallbackClass (string alias) { _alias = alias ; }

// InternalSubmissionCallback is the method that is called by
// RemotelyDelegatableObject.SubmissionCallback(). SubmissionCallback() is
// sent to the server via a delegate. You want the chat server to call
// when the Submission event occurs -- even if the submission is yours.
// The SubmissionEventHandler delegate wraps this function and is passed
// to the Add_Submission (SubmissionEventHandler delegate) member of
// the ChatCoordinator object. The .NET Remoting system handles the transfer
// of all information about the client object and channel necessary to
// make a return remote call when the event occurs.
protected override void InternalSubmissionCallback (object sender,
SubmitEventArgs submitArgs)
{

// Block out your own submission.
// This simple chat server does not filter anything.
if (String.Compare(submitArgs.Contributor, _alias, true) == 0)
{
Console.WriteLine("Your message was broadcast.");
}
else
Console.WriteLine(submitArgs.Contributor
+ " says:\r\n"
+ new String('-', 80)
+ submitArgs.Contribution
+ "\r\n"
+ new String('-', 80)
+ "\r\n");
}

// This override ensures that if the object is idle for an extended
// period, waiting for messages, it won't lose its lease. Without this
// override (or an alternative, such as implementation of a lease
// sponsor), an idle object that inherits from MarshalByRefObject
// may be collected even though references to it still exist.
public override object InitializeLifetimeService()
{
return null;
}
}
Nov 17 '05 #1
3 1499
ja*****@texeme.com wrote:
ReadLine().

However, when I run it in the cmd window, it does not output any
Console.WriteLine()s ( even the "Hello" that I put as the first
statement in Main() ). Nothing prints to the command line!?!


Are you running the app in debug mode or release mode?

If you are running in debug mode then it will print to the
Output Window, just make sure it is visible and you will see your results.
Nov 17 '05 #2

I figured out why.

The project was originally a Windows form.

Then I added a console class and made that the startup.

But I had to change the project type to Console before it would perform
correctly.

PS - I'm surprised that a 'project setting' would affect the way code runs
rather than the code itself...

Eugene Vital wrote:
ja*****@texeme.com wrote:
ReadLine().

However, when I run it in the cmd window, it does not output any
Console.WriteLine()s ( even the "Hello" that I put as the first
statement in Main() ). Nothing prints to the command line!?!


Are you running the app in debug mode or release mode?

If you are running in debug mode then it will print to the
Output Window, just make sure it is visible and you will see your results.


--
Texeme Textcasting Technology
http://www.texeme.com
Nov 17 '05 #3

I figured out why.

The project was originally a Windows form.

Then I added a console class and made that the startup.

But I had to change the project type to Console before it would perform
correctly.

PS - I'm surprised that a 'project setting' would affect the way code runs
rather than the code itself...

Eugene Vital wrote:
ja*****@texeme.com wrote:
ReadLine().

However, when I run it in the cmd window, it does not output any
Console.WriteLine()s ( even the "Hello" that I put as the first
statement in Main() ). Nothing prints to the command line!?!


Are you running the app in debug mode or release mode?

If you are running in debug mode then it will print to the
Output Window, just make sure it is visible and you will see your results.


--
Texeme Textcasting Technology
http://www.texeme.com
Nov 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: jabailo | last post by:
This is driving me crazy. I finally got the Remoting sample chat application working almost. When I run the chat client in VS.NET it goes into an endless loop -- that's because I assume that...
1
by: Oz | last post by:
This is long. Bear with me, as I will really go through all the convoluted stuff that shows there is a problem with streams (at least when used to redirect stdout). The basic idea is that my...
7
by: shawnk | last post by:
Hello Everyone How do you format format numbers right-justified using Console.WriteLine(), i.e I need to line up numbers in vertical columns and the MSDN documentation is pretty poor Here is the...
9
by: Kim | last post by:
Below is a program sample from the book "Teach Yourself the C# Language in 21 Days." I've compiled the program and receieved no errors - but it does not do what is expected. I've compared it to...
3
by: billr | last post by:
Excuse me if you consider this a cross post, however, it was originally destined for this group not the vc.atl group, but somehow it went there instead of here! (obviously it was something I did, but...
5
by: portroe | last post by:
Hi I am using console.Writeline in my simple program. I do not however see anything happening in the output window when I debug, there are also no error messages, Has anybody a tip on what...
16
by: Caroline | last post by:
I am building a web application to gather user information then launch a process to calculate results. The process is a 3rd Party executable. I cannot get the process to start. Is there a...
1
by: John Wright | last post by:
I am running a console application that connects to an Access database (8 million rows) and converts it to a text file and then cleans and compacts the database. When it runs I get the following...
2
by: Sparky74 | last post by:
Hi. Can somebody please help me - I cannot get my TCP client application to close its socket one I attempt a send. It will close the socket fine if I don't call Send or BeginSend. Soon as I do, it...
11
by: Gustaf | last post by:
Some error handling code: catch (System.Xml.XmlException e) { Console.WriteLine("Error in " + e.SourceUri + ": " + e.Message); return; } The output:
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.