|
Is there a way to open a new console window in a Console Application? I'd like to display some output messages in a secondary screen rather than on the main one.
The alternative would be to display a form with a textbox...
Thanks.
|
|
|
|
|
How about : Process.Start("cmd.exe");
|
|
|
|
|
A console application can't have multiple windows like the windows environment. If you insist on your desing, you can make another console applcation that takes your output as arguments and display it in its own console window. In this case you can use Process.Start() ta launch your second console application.
Notice that your first application will have no control on the second one once it has started.
Regards
|
|
|
|
|
Hi, I've problem creating windows service, that can insert values into database using Sql-server 2000 and platform is ASP.NET 2.0 (C#), anyway I followed the whole code using from 'the code project' website; http://www.codeproject.com/cs/system/WindowsService.asp
I write the whole code below again, and please let me know, what's wrong...
Thanks.
// WindowsService.cs
using System;
using System.Diagnostics;
using System.ServiceProcess;
using System.Collections.Generic;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Configuration;
namespace WindowsService
{
class WindowsService : ServiceBase
{
///
/// Public Constructor for WindowsService.
/// - Put all of your Initialization code here.
///
public WindowsService()
{
this.ServiceName = "My Windows Service";
this.EventLog.Source = "My Windows Service";
this.EventLog.Log = "Application";
// These Flags set whether or not to handle that specific
// type of event. Set to true if you need it, false otherwise.
this.CanHandlePowerEvent = true;
this.CanHandleSessionChangeEvent = true;
this.CanPauseAndContinue = true;
this.CanShutdown = true;
this.CanStop = true;
if (!EventLog.SourceExists("My Windows Service"))
EventLog.CreateEventSource("My Windows Service", "Application");
}
///
/// The Main Thread: This is where your Service is Run.
///
static void Main()
{
ServiceBase.Run(new WindowsService());
Test.ConnectionManager.Instance().Cb_Wap_NewItem(); // I addded this part from my
}
///
/// Dispose of objects that need it here.
///
/// <param name="disposing" />Whether or not disposing is going on.
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
}
///
/// OnStart: Put startup code here
/// - Start threads, get inital data, etc.
///
/// <param name="args" />
protected override void OnStart(string[] args)
{
base.OnStart(args);
}
///
/// OnStop: Put your stop code here
/// - Stop threads, set final data, etc.
///
protected override void OnStop()
{
base.OnStop();
}
///
/// OnPause: Put your pause code here
/// - Pause working threads, etc.
///
protected override void OnPause()
{
base.OnPause();
}
///
/// OnContinue: Put your continue code here
/// - Un-pause working threads, etc.
///
protected override void OnContinue()
{
base.OnContinue();
}
///
/// OnShutdown(): Called when the System is shutting down
/// - Put code here when you need special handling
/// of code that deals with a system shutdown, such
/// as saving special data before shutdown.
///
protected override void OnShutdown()
{
base.OnShutdown();
}
///
/// OnCustomCommand(): If you need to send a command to your
/// service without the need for Remoting or Sockets, use
/// this method to do custom methods.
///
/// <param name="command" />Arbitrary Integer between 128 & 256
protected override void OnCustomCommand(int command)
{
// A custom command can be sent to a service by using this method:
//# int command = 128; //Some Arbitrary number between 128 & 256
//# ServiceController sc = new ServiceController("NameOfService");
//# sc.ExecuteCommand(command);
base.OnCustomCommand(command);
}
///
/// OnPowerEvent(): Useful for detecting power status changes,
/// such as going into Suspend mode or Low Battery for laptops.
///
/// <param name="powerStatus" />The Power Broadcase Status (BatteryLow, Suspend, etc.)
protected override bool OnPowerEvent(PowerBroadcastStatus powerStatus)
{
return base.OnPowerEvent(powerStatus);
}
///
/// OnSessionChange(): To handle a change event from a Terminal Server session.
/// Useful if you need to determine when a user logs in remotely or logs off,
/// or when someone logs into the console.
///
/// <param name="changeDescription" />
protected override void OnSessionChange(SessionChangeDescription changeDescription)
{
base.OnSessionChange(changeDescription);
}
private void InitializeComponent()
{
}
}
}
// WindowsServiceInstaller.cs
using System;
using System.ComponentModel;
using System.Configuration.Install;
using System.ServiceProcess;
namespace WindowsService
{
[RunInstaller(true)]
public class WindowsServiceInstaller : Installer
{
///
/// Public Constructor for WindowsServiceInstaller.
/// - Put all of your Initialization code here.
///
public WindowsServiceInstaller()
{
ServiceProcessInstaller serviceProcessInstaller = new ServiceProcessInstaller();
ServiceInstaller serviceInstaller = new ServiceInstaller();
//# Service Account Information
serviceProcessInstaller.Account = ServiceAccount.LocalSystem;
serviceProcessInstaller.Username = null;
serviceProcessInstaller.Password = null;
//# Service Information
serviceInstaller.DisplayName = "Test C# Windows Service";
serviceInstaller.StartType = ServiceStartMode.Automatic;
// This must be identical to the WindowsService.ServiceBase name
// set in the constructor of WindowsService.cs
serviceInstaller.ServiceName = "My Windows Service";
this.Installers.Add(serviceProcessInstaller);
this.Installers.Add(serviceInstaller);
}
}
}
// ConnectionManager.cs
using System;
using System.Collections;
using System.Text;
using System.Data.SqlClient;
using System.Configuration;
namespace Test
{
class ConnectionManager
{
private SqlConnection connectionSql = null;
private SqlCommand commandSql = null;
private SqlCommand commandSql2 = null;
private SqlDataReader dataReaderSql = null;
private SqlDataReader dataReaderSql2 = null;
private String queryString = String.Empty;
private ArrayList returnArrayList = null;
private ArrayList returnArrayList2 = null;
private ConnectionManager()
{
returnArrayList = new ArrayList();
returnArrayList2 = new ArrayList();
connectionSql = new SqlConnection("Server=localhost;Database=dbMsgBox;User Id=sa; password=1234");
}
public static ConnectionManager Instance()
{
return new ConnectionManager();
}
public void Cb_Wap_NewItem()
{
commandSql = new SqlCommand("Select Top 1(out_msg_id) from tbl_outbox ORDER BY out_msg_id DESC", connectionSql);
connectionSql.Open();
dataReaderSql = commandSql.ExecuteReader();
if (dataReaderSql.Read())
{
try
{
dataReaderSql.Close();
SqlDataReader reader = null;
string sql = "Select Top 1(out_msg_id) as last_id from tbl_outbox ORDER BY out_msg_id DESC";
SqlCommand command = new SqlCommand();
command.CommandText = sql;
command.Connection = connectionSql;
reader = command.ExecuteReader();
if (reader.Read())
{
long last_entried_data = Convert.ToInt64(reader[0]);
long new_entried_data;
new_entried_data = last_entried_data + 200;
long mobNo = 5555;
long in_msg_id = 6980;
string body = "habi zabi";
decimal stat = Convert.ToDecimal(0);
int msg_typ = 0;
int send_port = 3838;
reader.Close();
commandSql2 = new SqlCommand("SET IDENTITY_INSERT [tbl_Outbox] ON;insert into tbl_Outbox(out_msg_id,mobileno,in_msg_id,body,status,msg_type,send_port) values(" + new_entried_data + "," + mobNo + "," + in_msg_id + ",'" + body + "'," + stat + "," + msg_typ + "," + send_port + "); SET IDENTITY_INSERT [tbl_Outbox] OFF;", connectionSql);
dataReaderSql2 = commandSql2.ExecuteReader();
}
dataReaderSql2.Close();
connectionSql.Close();
}
catch (Exception e)
{
connectionSql.Close();
Cb_Wap_NewItem();
System.Console.WriteLine(e);
}
}
}
}
}
|
|
|
|
|
My experience with Windows services is that you have to login the service with a user account to use any network operations.
So try to change this:
//# Service Account Information
serviceProcessInstaller.Account = ServiceAccount.LocalSystem;
serviceProcessInstaller.Username = null;
serviceProcessInstaller.Password = null;
into:
//# Service Account Information
serviceProcessInstaller.Account = ServiceAccount.User;
serviceProcessInstaller.Username = yourusername;
serviceProcessInstaller.Password = yourpassword;
With the correct values of course...
|
|
|
|
|
Hi to all,
How to Save TreeView Data, so that saved data can be Load in the TreeView next-time?
TreeView data contain all TreeView related data i.e. No. of Nodes, Node Name, Tag Value of Each Node. Tag value contains different objects of User-Defined Classes.
So how can I do this?
Please help me.
Thanks & Best Regards,
Aniket Salunkhe
|
|
|
|
|
Save it to a database, file or some other persistent storage mechanism.
only two letters away from being an asset
|
|
|
|
|
|
Hi, Comments about what ?
|
|
|
|
|
What actually do u want to do?
And comments about wht?
Thanks & Regards,
Pramod
"Everyone is a genius at least once a year"
|
|
|
|
|
Comments:
shyamy wrote: int Count=txtEnter.Text.Length,i=0;
Local variables are generally named with the first character in lower case, e.g. count instead of Count .
There is no reason to initalise the variable i , as you are not using it before you initialise it again in the loop.
for(i=Count;i>0;i--)
Why are you looping from Count to 1 instead of from Count-1 to 0?
txtChange.Text+=myString.Substring(i-1,1);
Use a StringBuilder to build the string. That way you don't create so many string objects. Using the += operator to concatenate strings scales very badly; the execution time increases exponetially for each character you add.
Instead of using SubString , use the indexer to get the character: myString[i-1] , that way you use a char value to handle the character instead of creating another string object.
---
b { font-weight: normal; }
|
|
|
|
|
private void btnChange_Click(object sender, System.EventArgs e)<br />
{<br />
int Count=txtEnter.Text.Length;<br />
<br />
int i=0;<br />
<br />
string myString=txtEnter.Text;<br />
<br />
for(i=Count;i>0;i--)<br />
{<br />
txtChange.Text+=myString.Substring(i-1,1);<br />
}<br />
}<br />
<br />
<br />
private void btnExit_Click(object sender, System.EventArgs e)<br />
{<br />
this.Close();<br />
}
Hope this helps
"My advice to you is to get married. If you find a good wife, you will be happy; if not, you will become a philosopher." Socrates
|
|
|
|
|
Hi,
I am trying to print multiple labels using response.binarywrite() and i am getting only 1 image.I am attaching the code with this please help me out.
protected void Page_Load(object sender, EventArgs e)
{
int count = Convert.ToInt32(Session["PkgCount"]);
for (int i = 0; i
|
|
|
|
|
Are you trying to send multiple images in the same response? That is not possible. If you want them in the same response, you have to create a larger image and draw the images onto it, so that you can send it as a single image.
---
b { font-weight: normal; }
|
|
|
|
|
Hi guffa,
I dont want to dispaly it as a single response. It is a response from UPS server and i am trying to write it in to a browser. Please look in to the code and suggest me a good solution.
|
|
|
|
|
I can't suggest any solution, as I don't know what it is that you are trying to do.
---
b { font-weight: normal; }
|
|
|
|
|
Hi Guffa,
I am trying to print multiple label images in case of ups multi label implementaion. The response i get in XML schema and from that i parsedout the label images and stored in an array and from that array i am trying to print the labels in to Response. So many images are there and i am getting only one image the rest are getting overwritten. Because of this i am not able to release the product. i searched a lot in the net but i havn't got a good result from there. Please help me out with this problem
|
|
|
|
|
Ok, so then you are trying to show them in a single response, although you said that you didn't.
A response can only consist of one item. One html document, one image or one file. What you have managed to create is a response that contains one image with a lot of garbage data appended to it. The garbage data is of course the other images that you tried to put in the same request as the first image. The other images are not being overwritten, as you thought, only ignored.
As I explained before, you can't send multiple images in one response. If you have multiple images and want to send them in the same response, you have to put them together into a single image.
---
b { font-weight: normal; }
|
|
|
|
|
Hi Guffa,
Could you please tell me how to put the multiple images together. I tried out with an arraylist but that was a failure. Please advice me on this
|
|
|
|
|
Create a Bitmap large enough to contain the separate images, get a graphics object for the Bitmap by using the FromImage method of the Graphics class, and use that to draw the separate images onto the Bitmap. Save the Bitmap to the response stream.
---
b { font-weight: normal; }
|
|
|
|
|
we have already converted it to .bmp format in the prevous page. I am reallu stuck up with this problem.
Bitmap bmp = new Bitmap((Bitmap)System.Drawing.Image.FromStream(mem));
MemoryStream label = new MemoryStream();
bmp.Save(label, format);
please tell me a possible solution.
|
|
|
|
|
A Bitmap object is not the same as a .bmp file.
Read my previous post for the solution.
---
b { font-weight: normal; }
|
|
|
|
|
Hi im writing a classes for a TcpConnection that works with the Socket-Mehtods.
In my class i wanna fire an event when i got Bytes and i do that with the BeginReceive- and EndReceive-Methods.
But when i fire an event from the AsyncCallBack-Methode that i have to set with the Socket.BeginReceive-Methode, then i got and InvalidOperationException when i handle
the event in an Form
Here the class example
<code>
public class TcpConnection {
public delegate void ReceiveDataEventHandler( byte[] e );
public event ReceiveDataEventHandler ReceiveData;
public Socket m_connectionSocket;
public byte[] m_receiveBuffer;
public TcpConnection() {
m_connectionSocket = new Socket(AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp);
}
public void startReceiving() {
m_receiveBuffer = new byte[ m_connectionSocket.ReceiveBufferSize ];
m_connectionSocket.BeginReceive( m_receiveBuffer, 0, m_receiveBuffer.Length,
SocketFlags.None, new AsyncCallback( receiveDataBytes ), m_connectionSocket );
}
private void receiveDataBytes( IAsyncResult asyncResult ) {
Socket thisSocket = ( Socket ) asyncResult.AsyncState;
int dataBufferLength = thisSocket.EndReceive( asyncResult );
byte[] dataBuffer = new byte[ dataBufferLength ];
Array.Copy( m_receiveBuffer, dataBuffer, dataBufferLength );
if( ReceiveData != null ) {
ReceiveData( dataBuffer );
}
thisSocket.BeginReceive( m_receiveBuffer, 0, m_receiveBuffer.Length, SocketFlags.None,
new AsyncCallback( receiveDataBytes ), thisSocket );
}
}
</code>
and here the handling of the event in a form
<code>
public partial class Form1 : Form {
private Socket localSocket = new Socket( AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp );
public Form1() {
InitializeComponent();
Socket newConnection = localSocket.Accept();
TcpConnection myConnection = new TcpConnection( newConnection );
myConnection.ReceiveData += new TcpConnection.ReceiveDataEventHandler( receiveDataEvent );
myConnection.startReceiving();
}
private void receiveDataEvent( byte[] data ) {
this.Text = System.Text.Encoding.ASCII.GetString( data );
}
}
</code>
My question is now.....how do i fire the event right, so that i can access the form-elements normaly like in the other eventhandler-methods
-- modified at 11:01 Monday 27th November, 2006
|
|
|
|
|
The problem is that you fire the event on a thread other than the main UI thread and it's not allowed to access UI controls from threads other the one they were created on as this can trigger unexpected behaviour e.g. freezing your app. You have to handle this on your event handler in the following way:
private void receiveDataEvent(byte[] data)
{
if (this.InvokeRequired)
{
this.Invoke(new ReceiveDataEventHandler(this.receiveDataEvent), data);
}
else
{
}
}
For some more information on invoking take a look at the following article: What's up with BeginInvoke?[^]
Last but not least: Please always put pre tags around multiline code snippets as this preserves indentation and therefor makes the snippet much more readable.
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
hi Stefan, thx for the quick answer =)
OK, i see how that work with this.InvokeRequired...
...but can you tell me what i must do so that i can use my events like the other events fired from microsoft-Classes,
example -> System.IO.Ports.SerialPort.DataReceived-Event
they dont need to go over this.InvokeRequired =/
|
|
|
|
|