|
You MUST have at least one Main method in your application to act as an entry point.
If you have more than one Main method in your application, you can specify the startup object from the project's properties. But it's not the case here.
[Edit]Xmen is correct. I was talking about executables. I forgot about libraries.[/Edit]
The method you have here is a static constructor, a method that will be called only the first time you use that class in any way.
You can create objects from that class normally just like any other classes.
static void Main(string[] args)
{
StaticTest s1 = new StaticTest();
StaticTest s2 = new StaticTest();
StaticTest s3 = new StaticTest();
}
Eslam Afifi
modified on Saturday, March 14, 2009 12:09 PM
|
|
|
|
|
Set project Output Type to Class Library, then you wont need Main
TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L
%^]*IRXD#@GKCQ`R\^SF_WcHbORY87֦ʻ6ϣN8ȤBcRAV\Z^&SU~%CSWQ@#2
W_AD`EPABIKRDFVS)EVLQK)JKSQXUFYK[M`UKs*$GwU#(QDXBER@CBN%
Rs0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-iTV.C\y<pjxsg-b$f4ia>
--------------------------------------------------------
128 bit encrypted signature, crack if you can
|
|
|
|
|
Xmen is right, but, of course, your code will not then execute, it will need to be imported into a project that DOES have a main method, which then will create instances of these classes and call them. There is no way to get C# code to execute without a static void main method, somewhere, unless it is in a class library that uses COM and thus can be loaded by a C++ app ( which would have an int main method ).
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
Simple, write a compiler that uses a different name.
|
|
|
|
|
Hi,
I have the client and Udp server communicate with each other.Now im not getting the exception "The existing connection was forcibly closed by the remote host".This is because i have defined the server in a separate project.
The client is now able to communicate with 1 server at one ip and port.But i want the client to call another udp server at another port but same ip.For eg:the client is communicating with udp server at port 10001.After every 15 secs the client should connect with the servers at different ports(10002,10003 etc)
How i can do this?Please give me your suggestions
|
|
|
|
|
Hi,
what could be the problem? duplicate what you already have. And if there are any blocking calls, consider using an extra thread/backgroundworker.
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
|
|
|
|
|
"Hi, I have the client and Udp server communicate with each other.Now im not getting the exception "The existing connection was forcibly closed by the remote host".This is because i have defined the server in a separate project."
- Most likely because you are using UDP and not TCP (if thats what was used before) UDP doesnt care about "connections" etc, it just sends/recieves to/from endpoints. Not because you moved the server part into a seperate project...
"The client is now able to communicate with 1 server at one ip and port.But i want the client to call another UDP server at another port but same ip.For eg:the client is communicating with udp server at port 10001.After every 15 secs the client should connect with the servers at different ports(10002,10003 etc)"
- You will have to define another endpoint for the UDP sending socket (client) with a different port, tis all. If you still are having problems, please post up some code; it might help clear things up.
modified on Saturday, March 14, 2009 1:30 PM
|
|
|
|
|
Hi,
If iam defining a new endpoint the client will be able to call yet another udp server.But i want the client to recursively call the servers at different port for every 15 secs.
//client
private void SendMessage()
{
try
{
listBox6.Items.Add("Connecting....");
IPEndPoint ipep = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 10001);
Socket sock = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
sock.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.SendBuffer, 1);
listBox6.Items.Add("Connected");
byte[] data = new byte[1024];
String snd = "hello";
data = Encoding.ASCII.GetBytes(snd);
listBox6.Items.Add("Transmitting...");
sock.SendTo(data, 0,data.Length, SocketFlags.None, ipep);
listBox6.Items.Add("Sent...");
EndPoint tmpRemote = (EndPoint)ipep;
listBox6.Items.Add("Message received from {0}:");
listBox6.Items.Add(ipep.ToString());
data = new byte[1024];
int recv = sock.ReceiveFrom(data, 0, data.Length, SocketFlags.None, ref tmpRemote);
String zz=Encoding.ASCII.GetString(data, 0, recv);
listBox6.Items.Add(zz);
if (zz == "Welcome to the Server")
{
lb9.Text = "Active";
lb9.BackColor = Color.Green;
}
else{
lb9.Text = "Inactive";
lb9.BackColor=Color.Red;
}
}
catch (SocketException e)
{
MessageBox.Show(e.Message);
}
}
//server
public static void start_server()
{
IPEndPoint ipep = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 10001);
Socket newsock = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
newsock.Bind(ipep);
Console.WriteLine("Waiting for a client...");
while (true)
{
try
{
EndPoint tmpRemote = (EndPoint)ipep;
byte[] data = new byte[1024];
Console.WriteLine("hai");
int recv = newsock.ReceiveFrom(data, 0, data.Length, SocketFlags.None, ref tmpRemote);
Console.WriteLine("gfgjfk");
Console.WriteLine("Message received from {0}:", tmpRemote.ToString());
Console.WriteLine(Encoding.ASCII.GetString(data, 0, recv));
data = new byte[1024];
string ss = "Welcome to the Server";
data = Encoding.ASCII.GetBytes(ss);
newsock.SendTo(data, 0, data.Length, SocketFlags.None, tmpRemote);
Console.WriteLine("\nSent Acknowledgement");
}
catch (SocketException e)
{
Console.WriteLine(e.Message);
}
start_server();
}
}
}
|
|
|
|
|
did you try my last[^] suggestion?
|
|
|
|
|
Hi,
I used multithreading concept so the client is able to communicate with any number of servers.Using the same concept i tried to call the 2nd server after 10 secs.When it comes to the client the 2nd time it gives"Invalid OperationException Cross-thread operation not valid: Control 'listBox6' accessed from a thread other than the thread it was created on."
//server
public UdpServer()
{
try
{
Thread startServer = new Thread(new ThreadStart(start_server));
startServer.Start();
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
try
{
Thread.Sleep(10000);
startServer2 = new Thread(new hreadStart(start_server2));
startServer2.Start();
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
public static void start_server()
{
IPEndPoint ipep = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 10001);
Socket newsock = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
newsock.Bind(ipep);
Console.WriteLine("Waiting for a client...");
while (true)
{
try
{
EndPoint tmpRemote = (EndPoint)ipep;
byte[] data = new byte[1024];
Console.WriteLine("hai");
int recv = newsock.ReceiveFrom(data, 0, data.Length, SocketFlags.None, ref tmpRemote);
Console.WriteLine("gfgjfk");
Console.WriteLine("Message received from {0}:", tmpRemote.ToString());
Console.WriteLine(Encoding.ASCII.GetString(data, 0, recv));
data = new byte[1024];
string ss = "Welcome to the Server";
data = Encoding.ASCII.GetBytes(ss);
newsock.SendTo(data, 0, data.Length, SocketFlags.None, tmpRemote);
Console.WriteLine("\nSent Acknowledgement");
}
catch (SocketException e)
{
Console.WriteLine(e.Message);
}
}
}
public static void start_server2()
{
IPEndPoint ipep1 = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 10002);
Socket newsock1 = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
newsock1.Bind(ipep1);
Console.WriteLine("Waiting for a client2...");
while (true)
{
try
{
EndPoint tmpRemote1 = (EndPoint)ipep1;
byte[] data = new byte[1024];
Console.WriteLine("hai");
int recv = newsock1.ReceiveFrom(data, 0, data.Length, SocketFlags.None, ref tmpRemote1);
Console.WriteLine("gfgjfk");
Console.WriteLine("Message received from {0}:", tmpRemote1.ToString());
Console.WriteLine(Encoding.ASCII.GetString(data, 0, recv));
data = new byte[1024];
string ss = "Welcome to the Server";
data = Encoding.ASCII.GetBytes(ss);
newsock1.SendTo(data, 0, data.Length, SocketFlags.None, tmpRemote1);
Console.WriteLine("\nSent Acknowledgement");
}
catch (SocketException e)
{
Console.WriteLine(e.Message);
}
}
} //client
private void SendMessage()
{
try
{
listBox6.Items.Add("Connecting....");
IPEndPoint ipep = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 10001);
Socket sock = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
sock.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.SendBuffer, 1);
listBox6.Items.Add("Connected");
byte[] data = new byte[1024];
String snd = "hello";
data = Encoding.ASCII.GetBytes(snd);
listBox6.Items.Add("Transmitting...");
sock.SendTo(data, 0,data.Length, SocketFlags.None, ipep);
listBox6.Items.Add("Sent...");
EndPoint tmpRemote = (EndPoint)ipep;
listBox6.Items.Add("Message received from {0}:");
listBox6.Items.Add(ipep.ToString());
data = new byte[1024];
int recv = sock.ReceiveFrom(data, 0, data.Length, SocketFlags.None, ref tmpRemote);
String zz=Encoding.ASCII.GetString(data, 0, recv);
listBox6.Items.Add(zz);
if (zz == "Welcome to the Server")
{
lb9.Text = "Active";
lb9.BackColor = Color.Green;
}
else{
lb9.Text = "Inactive";
lb9.BackColor=Color.Red;
}
}
catch (SocketException e)
{
MessageBox.Show(e.Message);
}
}
private void SendMessage1()
{
try
{
listBox6.Items.Add("Connecting....");
IPEndPoint ipep = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 10002);
}} I am calling the SendMessage1 in a timer event
[code] private void tim_Elapsed(object sender,ElapsedEventArgs e)
{
SendMessage1();
}
Please help me with this
modified on Sunday, March 15, 2009 4:13 AM
|
|
|
|
|
Hi
The following code gives me the output:
Waiting for client...
hai
Waiting for client2.....
hai
Message received from...
hello
Sent ackn....
hai
Message received from...
server
Sent ackn....
I want it to be like:
Waiting for client...
hai
Message received from...
hello
Sent ackn....
Waiting for client 2...
I tried to change but im getting"the existing connection was forcibly closed by the remote host"..Please help me with this
//client
public void SendMessage()
{
try
{
listBox6.Items.Add("Connecting....");
IPEndPoint ipep = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 10001);
Socket sock = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
sock.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.SendBuffer, 1);
listBox6.Items.Add("Connected");
byte[] data = new byte[1024];
String snd = "hello";
data = Encoding.ASCII.GetBytes(snd);
listBox6.Items.Add("Transmitting...");
sock.SendTo(data, 0,data.Length, SocketFlags.None, ipep);
listBox6.Items.Add("Sent...");
EndPoint tmpRemote = (EndPoint)ipep;
listBox6.Items.Add("Message received from {0}:");
listBox6.Items.Add(ipep.ToString());
data = new byte[1024];
int recv = sock.ReceiveFrom(data, 0, data.Length, SocketFlags.None, ref tmpRemote);
String zz=Encoding.ASCII.GetString(data, 0, recv);
listBox6.Items.Add(zz);
if (zz == "Welcome to the Server")
{
lb9.Text = "Active";
lb9.BackColor = Color.Green;
}
else{
lb9.Text = "Inactive";
lb9.BackColor=Color.Red;
}
}
catch (SocketException e)
{
MessageBox.Show(e.Message);
}
}
public void SendMessage1()
{
}
//server
public UdpServer()
{
try
{
startServer = new Thread(new ThreadStart(start_server));
startServer.Start();
}
catch (Exception e)
{
Console.WriteLine(e.Message);
startServer.Abort();
}
try
{
startServer2 = new Thread(new ThreadStart(start_server2));
startServer2.Start();
}
catch (Exception e)
{
Console.WriteLine(e.Message);
startServer2.Abort();
}
}
public static void start_server()
{
IPEndPoint ipep = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 10001);
Socket newsock = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
newsock.Bind(ipep);
Console.WriteLine("Waiting for a client...");
while (true)
{
try
{
EndPoint tmpRemote = (EndPoint)ipep;
byte[] data = new byte[1024];
Console.WriteLine("hai");
int recv = newsock.ReceiveFrom(data, 0, data.Length, SocketFlags.None, ref tmpRemote);
Console.WriteLine("gfgjfk");
Console.WriteLine("Message received from {0}:", tmpRemote.ToString());
Console.WriteLine(Encoding.ASCII.GetString(data, 0, recv));
data = new byte[1024];
string ss = "Welcome to the Server";
data = Encoding.ASCII.GetBytes(ss);
newsock.SendTo(data, 0, data.Length, SocketFlags.None, tmpRemote);
Console.WriteLine("\nSent Acknowledgement"); }
catch (SocketException e)
{
Console.WriteLine(e.Message);
}
}
}
public static void start_server2()
{
}
|
|
|
|
|
Hi
I used the Thread.Sleep()
public UdpServer()
{
try
{
startServer = new Thread(new ThreadStart(start_server));
startServer.Start();
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
try
{
Thread.Sleep(20000);
startServer2 = new Thread(new ThreadStart(start_server2));
startServer2.Start();
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
} Im getting the output as
Waiting for client...
hai
Message received....
hello
Sent ack
Waiting for client2...
hai
At this it shows"existing connection was forcibly closed by the remote host".Please give me your suggestion
|
|
|
|
|
I have made some user controls. I will be using them in another application in C# where these will be added on the form dynamically at the click of a button. The sizes of the user controls differ from one another.
The problem is that when I add them dynamically it aligns itself at the top left corner. I want it to automatically align itself to centre of the main form and when I resize the form, it should realign itself.
I have tried setting its dock property to fill but it doesn't help at all.
Always Keep Smiling.
Yours Pankaj Nikam
|
|
|
|
|
use Resize event of form and put all controls in a panel then update its location. eg
panel.Location = new Point(this.Width/2 - panel.Width/2, this.Height/2-panel.Height/2);
TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L
%^]*IRXD#@GKCQ`R\^SF_WcHbORY87֦ʻ6ϣN8ȤBcRAV\Z^&SU~%CSWQ@#2
W_AD`EPABIKRDFVS)EVLQK)JKSQXUFYK[M`UKs*$GwU#(QDXBER@CBN%
Rs0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-iTV.C\y<pjxsg-b$f4ia>
--------------------------------------------------------
128 bit encrypted signature, crack if you can
|
|
|
|
|
Thank you so much.
Always Keep Smiling.
Yours Pankaj Nikam
|
|
|
|
|
Put everything into a panel, and set that panel's Anchor property to none.
|
|
|
|
|
Hey all,
I am currently in the middle of writing a custom windows form. (.Net 2.0).
I have removed the default border from the form, changed this to a Sizable Border and also set the text of the form to blank so to remove the window caption box.
I have now added a custom close, minimize, and maximize button to my form. All works well except for the maximize. On clicking this button, i do wish the form to maximize, which it does, however; it also maxmizes over the top of the task bar. How would i go about stopping this, and letting us view the task bar at all times?
I could set the size on the window, however; that would still show the resize borders on the form, which i want to be hidden on maximized state.
Help would be greatly appreciated.
Thanks
TF
|
|
|
|
|
If this.WindowState = System.Windows.Forms.FormWindowState.Maximized doesn't work for you then you're working too hard.
|
|
|
|
|
It works to a certain extent... It maximizes the window, however; it also maximizes over the top of the task bar
|
|
|
|
|
Works fine for me, doesn't cover the task bar.
|
|
|
|
|
Yeah, I have seen some anomalies over the years, and never figured out all the details; some of these are factors in the end result:
- Windows version
- taskbar location (mine is typically at the left)
- taskbar mode (auto-hide, never hide; I prefer never hide assuming monitor sufficiently large)
- the order in which Windows properties get set
And for some applications, one wants to cover the task bar whatever the system settings are (e.g. a slide show)
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
|
|
|
|
|
Hi,
with a standard Form, when you look at Form.Bounds in the Resize handler, you will notice maximize typically sets the corners off-screen, e.g. the top left corner to (-4,-4) which is fine when you have a single monitor (the maximized form would protrude on a second monitor if you watch closely).
You could forego the built-in maximizing, and do it yourself in as much as you need it.
Also SystemInformation.PrimaryMonitorMaximizedWindowSize might be of interest.
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
|
|
|
|
|
Thanks
Manage to figure it out using SystemInformation.PrimaryMonitorMaximizedWindowSize and writing the maximze code by hand.
|
|
|
|
|
Set this property in your load event, or make it a user option: this.MaximizedBounds = SystemInformation.WorkingArea;
|
|
|
|
|
hello,
i wrote an application in c# that starts automaticaly when computer starts.
i allready have code that prevents the application from running more than
once as follows:
static void Main()
{
Boolean firstInstance = false;
string safeName = "xxx";
Mutex mutex = new Mutex(true, safeName, out firstInstance);
if (!firstInstance) return;
}
now when i publish a new version (i set the revision to increase
automaticaly) and run the setup file all is fine but the old application
still remains.
i get two copies running , one new and one old.
is there a way to tell the old version to close ? like an external event?
i am using only visual studio tools.
thanks in advance
avi
|
|
|
|
|