473,322 Members | 1,778 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,322 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;
}
}
Jul 21 '05 #1
4 2169
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.
Jul 21 '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
Jul 21 '05 #3
On Mon, 20 Jun 2005 22:09:38 -0700, "ja*****@texeme.com"
<ja*****@texeme.com> wrote:

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...


Could it be that the project type affects the way the code is
compiled?

rossum
[snip]

The ultimate truth is that there is no ultimate truth
Jul 21 '05 #4
> PS - I'm surprised that a 'project setting' would affect the way code runs
rather than the code itself...
That is because it changes the fundemental type of the exe. A windows
program does not start with an attached console. A console program does.

--
William Stacey [MVP]

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

Jul 21 '05 #5

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

Similar topics

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...
3
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...
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...
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: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.